/*
脚本引用 https://raw.githubusercontent.com/DualSubs/YouTube/main/js/YouTube.request.js
*/
console.log("🍿 DualSubs: ▶ YouTube Request");
const e = (function () {
  if ("undefined" != typeof $environment && $environment["surge-version"])
    return "Surge";
  if ("undefined" != typeof $environment && $environment["stash-version"])
    return "Stash";
  if ("undefined" != typeof module && module.exports) return "Node.js";
  if ("undefined" != typeof $task) return "Quantumult X";
  if ("undefined" != typeof $loon) return "Loon";
  if ("undefined" != typeof $rocket) return "Shadowrocket";
  if ("undefined" != typeof Egern) return "Egern";
})();
class a {
  static name = "Lodash";
  static version = "1.2.2";
  static about() {
    return console.log(`\n🟧 ${this.name} v${this.version}\n`);
  }
  static get(e = {}, a = "", t = void 0) {
    Array.isArray(a) || (a = this.toPath(a));
    const n = a.reduce((e, a) => Object(e)[a], e);
    return void 0 === n ? t : n;
  }
  static set(e = {}, a = "", t) {
    return (
      Array.isArray(a) || (a = this.toPath(a)),
      (a
        .slice(0, -1)
        .reduce(
          (e, t, n) =>
            Object(e[t]) === e[t]
              ? e[t]
              : (e[t] = /^\d+$/.test(a[n + 1]) ? [] : {}),
          e
        )[a[a.length - 1]] = t),
      e
    );
  }
  static unset(e = {}, a = "") {
    return (
      Array.isArray(a) || (a = this.toPath(a)),
      a.reduce(
        (e, t, n) => (n === a.length - 1 ? (delete e[t], !0) : Object(e)[t]),
        e
      )
    );
  }
  static toPath(e) {
    return e
      .replace(/\[(\d+)\]/g, ".$1")
      .split(".")
      .filter(Boolean);
  }
  static escape(e) {
    const a = {
      "&": "&amp;",
      "<": "&lt;",
      ">": "&gt;",
      '"': "&quot;",
      "'": "&#39;",
    };
    return e.replace(/[&<>"']/g, (e) => a[e]);
  }
  static unescape(e) {
    const a = {
      "&amp;": "&",
      "&lt;": "<",
      "&gt;": ">",
      "&quot;": '"',
      "&#39;": "'",
    };
    return e.replace(/&amp;|&lt;|&gt;|&quot;|&#39;/g, (e) => a[e]);
  }
}
class t {
  static name = "Storage";
  static version = "1.1.0";
  static about() {
    return s("", `🟧 ${this.name} v${this.version}`, "");
  }
  static data = null;
  static dataFile = "box.dat";
  static #e = /^@(?<key>[^.]+)(?:\.(?<path>.*))?$/;
  static getItem(t = new String(), n = null) {
    let s = n;
    if (!0 === t.startsWith("@")) {
      const { key: e, path: n } = t.match(this.#e)?.groups;
      t = e;
      let r = this.getItem(t, {});
      "object" != typeof r && (r = {}), (s = a.get(r, n));
      try {
        s = JSON.parse(s);
      } catch (e) {}
    } else {
      switch (e) {
        case "Surge":
        case "Loon":
        case "Stash":
        case "Egern":
        case "Shadowrocket":
          s = $persistentStore.read(t);
          break;
        case "Quantumult X":
          s = $prefs.valueForKey(t);
          break;
        case "Node.js":
          (this.data = this.#a(this.dataFile)), (s = this.data?.[t]);
          break;
        default:
          s = this.data?.[t] || null;
      }
      try {
        s = JSON.parse(s);
      } catch (e) {}
    }
    return s ?? n;
  }
  static setItem(t = new String(), n = new String()) {
    let s = !1;
    if ("object" == typeof n) n = JSON.stringify(n);
    else n = String(n);
    if (!0 === t.startsWith("@")) {
      const { key: e, path: r } = t.match(this.#e)?.groups;
      t = e;
      let i = this.getItem(t, {});
      "object" != typeof i && (i = {}),
        a.set(i, r, n),
        (s = this.setItem(t, i));
    } else
      switch (e) {
        case "Surge":
        case "Loon":
        case "Stash":
        case "Egern":
        case "Shadowrocket":
          s = $persistentStore.write(n, t);
          break;
        case "Quantumult X":
          s = $prefs.setValueForKey(n, t);
          break;
        case "Node.js":
          (this.data = this.#a(this.dataFile)),
            (this.data[t] = n),
            this.#t(this.dataFile),
            (s = !0);
          break;
        default:
          s = this.data?.[t] || null;
      }
    return s;
  }
  static removeItem(t) {
    let n = !1;
    if (!0 === t.startsWith("@")) {
      const { key: e, path: s } = t.match(this.#e)?.groups;
      t = e;
      let r = this.getItem(t);
      "object" != typeof r && (r = {}),
        (keyValue = a.unset(r, s)),
        (n = this.setItem(t, r));
    } else
      switch (e) {
        case "Surge":
        case "Loon":
        case "Stash":
        case "Egern":
        case "Shadowrocket":
        case "Node.js":
        default:
          n = !1;
          break;
        case "Quantumult X":
          n = $prefs.removeValueForKey(t);
      }
    return n;
  }
  static clear() {
    let a = !1;
    switch (e) {
      case "Surge":
      case "Loon":
      case "Stash":
      case "Egern":
      case "Shadowrocket":
      case "Node.js":
      default:
        a = !1;
        break;
      case "Quantumult X":
        a = $prefs.removeAllValues();
    }
    return a;
  }
  static #a(e) {
    if (!this.isNode()) return {};
    {
      (this.fs = this.fs ? this.fs : require("fs")),
        (this.path = this.path ? this.path : require("path"));
      const a = this.path.resolve(e),
        t = this.path.resolve(process.cwd(), e),
        n = this.fs.existsSync(a),
        s = !n && this.fs.existsSync(t);
      if (!n && !s) return {};
      {
        const e = n ? a : t;
        try {
          return JSON.parse(this.fs.readFileSync(e));
        } catch (e) {
          return {};
        }
      }
    }
  }
  static #t(e = this.dataFile) {
    if (this.isNode()) {
      (this.fs = this.fs ? this.fs : require("fs")),
        (this.path = this.path ? this.path : require("path"));
      const a = this.path.resolve(e),
        t = this.path.resolve(process.cwd(), e),
        n = this.fs.existsSync(a),
        s = !n && this.fs.existsSync(t),
        r = JSON.stringify(this.data);
      n
        ? this.fs.writeFileSync(a, r)
        : s
        ? this.fs.writeFileSync(t, r)
        : this.fs.writeFileSync(a, r);
    }
  }
}
function n(t = {}) {
  switch (e) {
    case "Surge":
      t.policy && a.set(t, "headers.X-Surge-Policy", t.policy),
        s(
          "",
          `🚩 执行结束! 🕛 ${
            new Date().getTime() / 1e3 - $script.startTime
          } 秒`,
          ""
        ),
        $done(t);
      break;
    case "Loon":
      t.policy && (t.node = t.policy),
        s(
          "",
          `🚩 执行结束! 🕛 ${(new Date() - $script.startTime) / 1e3} 秒`,
          ""
        ),
        $done(t);
      break;
    case "Stash":
      t.policy &&
        a.set(t, "headers.X-Stash-Selected-Proxy", encodeURI(t.policy)),
        s(
          "",
          `🚩 执行结束! 🕛 ${(new Date() - $script.startTime) / 1e3} 秒`,
          ""
        ),
        $done(t);
      break;
    case "Egern":
    case "Shadowrocket":
    default:
      s("", "🚩 执行结束!", ""), $done(t);
      break;
    case "Quantumult X":
      t.policy && a.set(t, "opts.policy", t.policy),
        delete t["auto-redirect"],
        delete t["auto-cookie"],
        delete t["binary-mode"],
        delete t.charset,
        delete t.host,
        delete t.insecure,
        delete t.method,
        delete t.opt,
        delete t.path,
        delete t.policy,
        delete t["policy-descriptor"],
        delete t.scheme,
        delete t.sessionIndex,
        delete t.statusCode,
        delete t.timeout,
        t.body instanceof ArrayBuffer
          ? ((t.bodyBytes = t.body), delete t.body)
          : ArrayBuffer.isView(t.body)
          ? ((t.bodyBytes = t.body.buffer.slice(
              t.body.byteOffset,
              t.body.byteLength + t.body.byteOffset
            )),
            delete t.body)
          : t.body && delete t.bodyBytes,
        s("", "🚩 执行结束!", ""),
        $done(t);
      break;
    case "Node.js":
      s("", "🚩 执行结束!", ""), process.exit(1);
  }
}
const s = (...e) => console.log(e.join("\n"));
var r = {
    Switch: !0,
    Type: "Translate",
    Types: ["Official", "Translate"],
    Languages: ["EN", "ZH"],
    CacheSize: 50,
  },
  i = {
    breakLine: {
      "text/xml": "&#x000A;",
      "application/xml": "&#x000A;",
      "text/vtt": "\n",
      "application/vtt": "\n",
      "text/json": "\n",
      "application/json": "\n",
    },
  },
  l = { Settings: r, Configs: i },
  o = {
    Switch: !0,
    Type: "Official",
    Types: ["Translate", "External"],
    Languages: ["AUTO", "ZH"],
    AutoCC: !0,
    ShowOnly: !1,
  },
  u = {
    Languages: {
      BG: "bg-BG",
      CS: "cs",
      DA: "da-DK",
      DE: "de",
      EL: "el",
      EN: "en",
      "EN-GB": "en-GB",
      "EN-US": "en-US",
      "EN-US SDH": "en-US SDH",
      ES: "es",
      "ES-419": "es-419",
      "ES-ES": "es-ES",
      ET: "et-EE",
      FI: "fi",
      FR: "fr",
      HU: "hu-HU",
      ID: "id",
      IS: "is-IS",
      IT: "it",
      JA: "ja",
      KO: "ko",
      LT: "lt-LT",
      LV: "lv-LV",
      NL: "nl-NL",
      NO: "nb-NO",
      PL: "pl-PL",
      PT: "pt",
      "PT-PT": "pt-PT",
      "PT-BR": "pt-BR",
      RO: "ro-RO",
      RU: "ru-RU",
      SK: "sk-SK",
      SL: "sl-SI",
      SV: "sv-SE",
      YUE: "yue",
      "YUE-HK": "yue-HK",
      ZH: "zh",
      "ZH-HANS": "zh-Hans",
      "ZH-HK": "zh-Hant-HK",
      "ZH-HANT": "zh-Hant",
      "ZH-TW": "zh-TW",
    },
    translationLanguages: {
      DESKTOP: [
        {
          languageCode: "sq",
          languageName: { simpleText: "Shqip - 阿尔巴尼亚语" },
        },
        { languageCode: "ak", languageName: { simpleText: "Ákán - 阿肯语" } },
        {
          languageCode: "ar",
          languageName: { simpleText: "العربية - 阿拉伯语" },
        },
        {
          languageCode: "am",
          languageName: { simpleText: "አማርኛ - 阿姆哈拉语" },
        },
        {
          languageCode: "as",
          languageName: { simpleText: "অসমীয়া - 阿萨姆语" },
        },
        {
          languageCode: "az",
          languageName: { simpleText: "آذربايجان ديلی - 阿塞拜疆语" },
        },
        { languageCode: "ee", languageName: { simpleText: "Èʋegbe - 埃维语" } },
        {
          languageCode: "ay",
          languageName: { simpleText: "Aymar aru - 艾马拉语" },
        },
        {
          languageCode: "ga",
          languageName: { simpleText: "Gaeilge - 爱尔兰语" },
        },
        {
          languageCode: "et",
          languageName: { simpleText: "Eesti - 爱沙尼亚语" },
        },
        {
          languageCode: "or",
          languageName: { simpleText: "ଓଡ଼ିଆ - 奥里亚语" },
        },
        {
          languageCode: "om",
          languageName: { simpleText: "Afaan Oromoo - 奥罗莫语" },
        },
        {
          languageCode: "eu",
          languageName: { simpleText: "Euskara - 巴斯克语" },
        },
        {
          languageCode: "be",
          languageName: { simpleText: "Беларуская - 白俄罗斯语" },
        },
        {
          languageCode: "bg",
          languageName: { simpleText: "Български - 保加利亚语" },
        },
        {
          languageCode: "nso",
          languageName: { simpleText: "Sesotho sa Leboa - 北索托语" },
        },
        {
          languageCode: "is",
          languageName: { simpleText: "Íslenska - 冰岛语" },
        },
        { languageCode: "pl", languageName: { simpleText: "Polski - 波兰语" } },
        {
          languageCode: "bs",
          languageName: { simpleText: "Bosanski - 波斯尼亚语" },
        },
        { languageCode: "fa", languageName: { simpleText: "فارسی - 波斯语" } },
        {
          languageCode: "bho",
          languageName: { simpleText: "भोजपुरी - 博杰普尔语" },
        },
        {
          languageCode: "ts",
          languageName: { simpleText: "Xitsonga - 聪加语" },
        },
        {
          languageCode: "tt",
          languageName: { simpleText: "Татарча - 鞑靼语" },
        },
        { languageCode: "da", languageName: { simpleText: "Dansk - 丹麦语" } },
        { languageCode: "de", languageName: { simpleText: "Deutsch - 德语" } },
        {
          languageCode: "dv",
          languageName: { simpleText: "ދިވެހިބަސް - 迪维希语" },
        },
        { languageCode: "ru", languageName: { simpleText: "Русский - 俄语" } },
        { languageCode: "fr", languageName: { simpleText: "français - 法语" } },
        {
          languageCode: "sa",
          languageName: { simpleText: "संस्कृतम् - 梵语" },
        },
        {
          languageCode: "fil",
          languageName: { simpleText: "Filipino - 菲律宾语" },
        },
        { languageCode: "fi", languageName: { simpleText: "suomi - 芬兰语" } },
        {
          languageCode: "km",
          languageName: { simpleText: "ភាសាខ្មែរ - 高棉语" },
        },
        {
          languageCode: "ka",
          languageName: { simpleText: "ქართული - 格鲁吉亚语" },
        },
        {
          languageCode: "gu",
          languageName: { simpleText: "ગુજરાતી - 古吉拉特语" },
        },
        {
          languageCode: "gn",
          languageName: { simpleText: "Avañe'ẽ - 瓜拉尼语" },
        },
        {
          languageCode: "kk",
          languageName: { simpleText: "Қазақ тілі - 哈萨克语" },
        },
        {
          languageCode: "ht",
          languageName: { simpleText: "Kreyòl ayisyen - 海地克里奥尔语" },
        },
        { languageCode: "ko", languageName: { simpleText: "한국어 - 韩语" } },
        { languageCode: "ha", languageName: { simpleText: "هَوُسَ - 豪萨语" } },
        {
          languageCode: "nl",
          languageName: { simpleText: "Nederlands - 荷兰语" },
        },
        {
          languageCode: "gl",
          languageName: { simpleText: "Galego - 加利西亚语" },
        },
        {
          languageCode: "ca",
          languageName: { simpleText: "català - 加泰罗尼亚语" },
        },
        {
          languageCode: "cs",
          languageName: { simpleText: "čeština - 捷克语" },
        },
        {
          languageCode: "kn",
          languageName: { simpleText: "ಕನ್ನಡ - 卡纳达语" },
        },
        {
          languageCode: "ky",
          languageName: { simpleText: "кыргыз тили - 吉尔吉斯语" },
        },
        {
          languageCode: "xh",
          languageName: { simpleText: "isiXhosa - 科萨语" },
        },
        {
          languageCode: "co",
          languageName: { simpleText: "corsu - 科西嘉语" },
        },
        {
          languageCode: "hr",
          languageName: { simpleText: "hrvatski - 克罗地亚语" },
        },
        {
          languageCode: "qu",
          languageName: { simpleText: "Runa Simi - 克丘亚语" },
        },
        {
          languageCode: "ku",
          languageName: { simpleText: "Kurdî - 库尔德语" },
        },
        {
          languageCode: "la",
          languageName: { simpleText: "lingua latīna - 拉丁语" },
        },
        {
          languageCode: "lv",
          languageName: { simpleText: "latviešu valoda - 拉脱维亚语" },
        },
        {
          languageCode: "lo",
          languageName: { simpleText: "ພາສາລາວ - 老挝语" },
        },
        {
          languageCode: "lt",
          languageName: { simpleText: "lietuvių kalba - 立陶宛语" },
        },
        {
          languageCode: "ln",
          languageName: { simpleText: "lingála - 林加拉语" },
        },
        {
          languageCode: "lg",
          languageName: { simpleText: "Luganda - 卢干达语" },
        },
        {
          languageCode: "lb",
          languageName: { simpleText: "Lëtzebuergesch - 卢森堡语" },
        },
        {
          languageCode: "rw",
          languageName: { simpleText: "Kinyarwanda - 卢旺达语" },
        },
        {
          languageCode: "ro",
          languageName: { simpleText: "Română - 罗马尼亚语" },
        },
        {
          languageCode: "mt",
          languageName: { simpleText: "Malti - 马耳他语" },
        },
        {
          languageCode: "mr",
          languageName: { simpleText: "मराठी - 马拉地语" },
        },
        {
          languageCode: "mg",
          languageName: { simpleText: "Malagasy - 马拉加斯语" },
        },
        {
          languageCode: "ml",
          languageName: { simpleText: "മലയാളം - 马拉雅拉姆语" },
        },
        {
          languageCode: "ms",
          languageName: { simpleText: "bahasa Melayu - 马来语" },
        },
        {
          languageCode: "mk",
          languageName: { simpleText: "македонски јазик - 马其顿语" },
        },
        {
          languageCode: "mi",
          languageName: { simpleText: "te reo Māori - 毛利语" },
        },
        {
          languageCode: "mn",
          languageName: { simpleText: "Монгол хэл - 蒙古语" },
        },
        {
          languageCode: "bn",
          languageName: { simpleText: "বাংলা - 孟加拉语" },
        },
        { languageCode: "my", languageName: { simpleText: "ဗမာစာ - 缅甸语" } },
        { languageCode: "hmn", languageName: { simpleText: "Hmoob - 苗语" } },
        {
          languageCode: "af",
          languageName: { simpleText: "Afrikaans - 南非荷兰语" },
        },
        {
          languageCode: "st",
          languageName: { simpleText: "Sesotho - 南索托语" },
        },
        {
          languageCode: "ne",
          languageName: { simpleText: "नेपाली - 尼泊尔语" },
        },
        { languageCode: "no", languageName: { simpleText: "Norsk - 挪威语" } },
        {
          languageCode: "pa",
          languageName: { simpleText: "ਪੰਜਾਬੀ - 旁遮普语" },
        },
        {
          languageCode: "pt",
          languageName: { simpleText: "Português - 葡萄牙语" },
        },
        { languageCode: "ps", languageName: { simpleText: "پښتو - 普什图语" } },
        {
          languageCode: "ny",
          languageName: { simpleText: "chiCheŵa - 齐切瓦语" },
        },
        { languageCode: "ja", languageName: { simpleText: "日本語 - 日语" } },
        {
          languageCode: "sv",
          languageName: { simpleText: "Svenska - 瑞典语" },
        },
        {
          languageCode: "sm",
          languageName: { simpleText: "Gagana fa'a Samoa - 萨摩亚语" },
        },
        {
          languageCode: "sr",
          languageName: { simpleText: "Српски језик - 塞尔维亚语" },
        },
        {
          languageCode: "si",
          languageName: { simpleText: "සිංහල - 僧伽罗语" },
        },
        {
          languageCode: "sn",
          languageName: { simpleText: "ChiShona - 绍纳语" },
        },
        {
          languageCode: "eo",
          languageName: { simpleText: "Esperanto - 世界语" },
        },
        {
          languageCode: "sk",
          languageName: { simpleText: "slovenčina - 斯洛伐克语" },
        },
        {
          languageCode: "sl",
          languageName: { simpleText: "slovenščina - 斯洛文尼亚语" },
        },
        {
          languageCode: "sw",
          languageName: { simpleText: "Kiswahili - 斯瓦希里语" },
        },
        {
          languageCode: "gd",
          languageName: { simpleText: "Gàidhlig - 苏格兰盖尔语" },
        },
        {
          languageCode: "ceb",
          languageName: { simpleText: "Binisaya - 宿务语" },
        },
        {
          languageCode: "so",
          languageName: { simpleText: "Soomaaliga - 索马里语" },
        },
        {
          languageCode: "tg",
          languageName: { simpleText: "тоҷикӣ - 塔吉克语" },
        },
        {
          languageCode: "te",
          languageName: { simpleText: "తెలుగు - 泰卢固语" },
        },
        {
          languageCode: "ta",
          languageName: { simpleText: "தமிழ் - 泰米尔语" },
        },
        { languageCode: "th", languageName: { simpleText: "ไทย - 泰语" } },
        {
          languageCode: "ti",
          languageName: { simpleText: "ትግርኛ - 提格利尼亚语" },
        },
        {
          languageCode: "tr",
          languageName: { simpleText: "Türkçe - 土耳其语" },
        },
        {
          languageCode: "tk",
          languageName: { simpleText: "Türkmen - 土库曼语" },
        },
        {
          languageCode: "cy",
          languageName: { simpleText: "Cymraeg - 威尔士语" },
        },
        {
          languageCode: "ug",
          languageName: { simpleText: "ئۇيغۇرچە - 维吾尔语" },
        },
        {
          languageCode: "und",
          languageName: { simpleText: "Unknown - 未知语言" },
        },
        { languageCode: "ur", languageName: { simpleText: "اردو - 乌尔都语" } },
        {
          languageCode: "uk",
          languageName: { simpleText: "українська - 乌克兰语" },
        },
        {
          languageCode: "uz",
          languageName: { simpleText: "O'zbek - 乌兹别克语" },
        },
        {
          languageCode: "es",
          languageName: { simpleText: "Español - 西班牙语" },
        },
        {
          languageCode: "fy",
          languageName: { simpleText: "Frysk - 西弗里西亚语" },
        },
        {
          languageCode: "iw",
          languageName: { simpleText: "עברית - 希伯来语" },
        },
        {
          languageCode: "el",
          languageName: { simpleText: "Ελληνικά - 希腊语" },
        },
        {
          languageCode: "haw",
          languageName: { simpleText: "ʻŌlelo Hawaiʻi - 夏威夷语" },
        },
        { languageCode: "sd", languageName: { simpleText: "سنڌي - 信德语" } },
        {
          languageCode: "hu",
          languageName: { simpleText: "magyar - 匈牙利语" },
        },
        {
          languageCode: "su",
          languageName: { simpleText: "Basa Sunda - 巽他语" },
        },
        {
          languageCode: "hy",
          languageName: { simpleText: "հայերեն - 亚美尼亚语" },
        },
        { languageCode: "ig", languageName: { simpleText: "Igbo - 伊博语" } },
        {
          languageCode: "it",
          languageName: { simpleText: "Italiano - 意大利语" },
        },
        {
          languageCode: "yi",
          languageName: { simpleText: "ייִדיש - 意第绪语" },
        },
        { languageCode: "hi", languageName: { simpleText: "हिन्दी - 印地语" } },
        {
          languageCode: "id",
          languageName: { simpleText: "Bahasa Indonesia - 印度尼西亚语" },
        },
        { languageCode: "en", languageName: { simpleText: "English - 英语" } },
        {
          languageCode: "yo",
          languageName: { simpleText: "Yorùbá - 约鲁巴语" },
        },
        {
          languageCode: "vi",
          languageName: { simpleText: "Tiếng Việt - 越南语" },
        },
        {
          languageCode: "jv",
          languageName: { simpleText: "Basa Jawa - 爪哇语" },
        },
        {
          languageCode: "zh-Hant",
          languageName: { simpleText: "中文（繁體）- 中文（繁体）" },
        },
        {
          languageCode: "zh-Hans",
          languageName: { simpleText: "中文（简体）" },
        },
        {
          languageCode: "zu",
          languageName: { simpleText: "isiZulu - 祖鲁语" },
        },
        { languageCode: "kri", languageName: { simpleText: "Krìì - 克里语" } },
      ],
      MOBILE: [
        {
          languageCode: "sq",
          languageName: { runs: [{ text: "Shqip - 阿尔巴尼亚语" }] },
        },
        {
          languageCode: "ak",
          languageName: { runs: [{ text: "Ákán - 阿肯语" }] },
        },
        {
          languageCode: "ar",
          languageName: { runs: [{ text: "العربية - 阿拉伯语" }] },
        },
        {
          languageCode: "am",
          languageName: { runs: [{ text: "አማርኛ - 阿姆哈拉语" }] },
        },
        {
          languageCode: "as",
          languageName: { runs: [{ text: "অসমীয়া - 阿萨姆语" }] },
        },
        {
          languageCode: "az",
          languageName: { runs: [{ text: "Azərbaycanca - 阿塞拜疆语" }] },
        },
        {
          languageCode: "ee",
          languageName: { runs: [{ text: "Eʋegbe - 埃维语" }] },
        },
        {
          languageCode: "ay",
          languageName: { runs: [{ text: "Aymar - 艾马拉语" }] },
        },
        {
          languageCode: "ga",
          languageName: { runs: [{ text: "Gaeilge - 爱尔兰语" }] },
        },
        {
          languageCode: "et",
          languageName: { runs: [{ text: "Eesti - 爱沙尼亚语" }] },
        },
        {
          languageCode: "or",
          languageName: { runs: [{ text: "ଓଡ଼ିଆ - 奥里亚语" }] },
        },
        {
          languageCode: "om",
          languageName: { runs: [{ text: "Oromoo - 奥罗莫语" }] },
        },
        {
          languageCode: "eu",
          languageName: { runs: [{ text: "Euskara - 巴斯克语" }] },
        },
        {
          languageCode: "be",
          languageName: { runs: [{ text: "Беларуская - 白俄罗斯语" }] },
        },
        {
          languageCode: "bg",
          languageName: { runs: [{ text: "Български - 保加利亚语" }] },
        },
        {
          languageCode: "nso",
          languageName: { runs: [{ text: "Sesotho sa Leboa - 北索托语" }] },
        },
        {
          languageCode: "is",
          languageName: { runs: [{ text: "Íslenska - 冰岛语" }] },
        },
        {
          languageCode: "pl",
          languageName: { runs: [{ text: "Polski - 波兰语" }] },
        },
        {
          languageCode: "bs",
          languageName: { runs: [{ text: "Bosanski - 波斯尼亚语" }] },
        },
        {
          languageCode: "fa",
          languageName: { runs: [{ text: "فارسی - 波斯语" }] },
        },
        {
          languageCode: "bho",
          languageName: { runs: [{ text: "भोजपुरी - 博杰普尔语" }] },
        },
        {
          languageCode: "ts",
          languageName: { runs: [{ text: "Xitsonga - 聪加语" }] },
        },
        {
          languageCode: "tt",
          languageName: { runs: [{ text: "Татарча - 鞑靼语" }] },
        },
        {
          languageCode: "da",
          languageName: { runs: [{ text: "Dansk - 丹麦语" }] },
        },
        {
          languageCode: "de",
          languageName: { runs: [{ text: "Deutsch - 德语" }] },
        },
        {
          languageCode: "dv",
          languageName: { runs: [{ text: "ދިވެހިބަސް - 迪维希语" }] },
        },
        {
          languageCode: "ru",
          languageName: { runs: [{ text: "Русский - 俄语" }] },
        },
        {
          languageCode: "fr",
          languageName: { runs: [{ text: "Français - 法语" }] },
        },
        {
          languageCode: "sa",
          languageName: { runs: [{ text: "संस्कृतम् - 梵语" }] },
        },
        {
          languageCode: "fil",
          languageName: { runs: [{ text: "Filipino - 菲律宾语" }] },
        },
        {
          languageCode: "fi",
          languageName: { runs: [{ text: "Suomi - 芬兰语" }] },
        },
        {
          languageCode: "km",
          languageName: { runs: [{ text: "ភាសាខ្មែរ - 高棉语" }] },
        },
        {
          languageCode: "ka",
          languageName: { runs: [{ text: "ქართული - 格鲁吉亚语" }] },
        },
        {
          languageCode: "gu",
          languageName: { runs: [{ text: "ગુજરાતી - 古吉拉特语" }] },
        },
        {
          languageCode: "gn",
          languageName: { runs: [{ text: "Avañe'ẽ - 瓜拉尼语" }] },
        },
        {
          languageCode: "kk",
          languageName: { runs: [{ text: "Қазақ тілі - 哈萨克语" }] },
        },
        {
          languageCode: "ht",
          languageName: { runs: [{ text: "海地克里奥尔语" }] },
        },
        {
          languageCode: "ko",
          languageName: { runs: [{ text: "한국말 - 韩语" }] },
        },
        {
          languageCode: "ha",
          languageName: { runs: [{ text: "هَوُسَ - 豪萨语" }] },
        },
        {
          languageCode: "nl",
          languageName: { runs: [{ text: "Nederlands - 荷兰语" }] },
        },
        {
          languageCode: "gl",
          languageName: { runs: [{ text: "Galego - 加利西亚语" }] },
        },
        {
          languageCode: "ca",
          languageName: { runs: [{ text: "Català - 加泰罗尼亚语" }] },
        },
        {
          languageCode: "cs",
          languageName: { runs: [{ text: "Čeština - 捷克语" }] },
        },
        {
          languageCode: "kn",
          languageName: { runs: [{ text: "ಕನ್ನಡ - 卡纳达语" }] },
        },
        {
          languageCode: "ky",
          languageName: { runs: [{ text: "Кыргызча - 吉尔吉斯语" }] },
        },
        {
          languageCode: "xh",
          languageName: { runs: [{ text: "isiXhosa - 科萨语" }] },
        },
        {
          languageCode: "co",
          languageName: { runs: [{ text: "Corsu - 科西嘉语" }] },
        },
        {
          languageCode: "hr",
          languageName: { runs: [{ text: "Hrvatski - 克罗地亚语" }] },
        },
        {
          languageCode: "qu",
          languageName: { runs: [{ text: "Runa Simi - 克丘亚语" }] },
        },
        {
          languageCode: "ku",
          languageName: { runs: [{ text: "Kurdî - 库尔德语" }] },
        },
        {
          languageCode: "la",
          languageName: { runs: [{ text: "lingua latīna - 拉丁语" }] },
        },
        {
          languageCode: "lv",
          languageName: { runs: [{ text: "Latviešu - 拉脱维亚语" }] },
        },
        {
          languageCode: "lo",
          languageName: { runs: [{ text: "ລາວ - 老挝语" }] },
        },
        {
          languageCode: "lt",
          languageName: { runs: [{ text: "Lietuvių - 立陶宛语" }] },
        },
        {
          languageCode: "ln",
          languageName: { runs: [{ text: "Lingála - 林加拉语" }] },
        },
        {
          languageCode: "lg",
          languageName: { runs: [{ text: "Luganda - 卢干达语" }] },
        },
        {
          languageCode: "lb",
          languageName: { runs: [{ text: "Lëtzebuergesch - 卢森堡语" }] },
        },
        {
          languageCode: "rw",
          languageName: { runs: [{ text: "Kinyarwanda - 卢旺达语" }] },
        },
        {
          languageCode: "ro",
          languageName: { runs: [{ text: "Română - 罗马尼亚语" }] },
        },
        {
          languageCode: "mt",
          languageName: { runs: [{ text: "Malti - 马耳他语" }] },
        },
        {
          languageCode: "mr",
          languageName: { runs: [{ text: "मराठी - 马拉地语" }] },
        },
        {
          languageCode: "mg",
          languageName: { runs: [{ text: "Malagasy - 马拉加斯语" }] },
        },
        {
          languageCode: "ml",
          languageName: { runs: [{ text: "മലയാളം - 马拉雅拉姆语" }] },
        },
        {
          languageCode: "ms",
          languageName: { runs: [{ text: "Bahasa Melayu - 马来语" }] },
        },
        {
          languageCode: "mk",
          languageName: { runs: [{ text: "македонски - 马其顿语" }] },
        },
        {
          languageCode: "mi",
          languageName: { runs: [{ text: "Māori - 毛利语" }] },
        },
        {
          languageCode: "mn",
          languageName: { runs: [{ text: "Монгол - 蒙古语" }] },
        },
        {
          languageCode: "bn",
          languageName: { runs: [{ text: "বাংলা - 孟加拉语" }] },
        },
        {
          languageCode: "my",
          languageName: { runs: [{ text: "ဗမာစာ - 缅甸语" }] },
        },
        {
          languageCode: "hmn",
          languageName: { runs: [{ text: "Hmoob - 苗语" }] },
        },
        {
          languageCode: "af",
          languageName: { runs: [{ text: "Afrikaans - 南非荷兰语" }] },
        },
        {
          languageCode: "st",
          languageName: { runs: [{ text: "Sesotho - 南索托语" }] },
        },
        {
          languageCode: "ne",
          languageName: { runs: [{ text: "नेपाली - 尼泊尔语" }] },
        },
        {
          languageCode: "no",
          languageName: { runs: [{ text: "Norsk - 挪威语" }] },
        },
        {
          languageCode: "pa",
          languageName: { runs: [{ text: "ਪੰਜਾਬੀ - 旁遮普语" }] },
        },
        {
          languageCode: "pt",
          languageName: { runs: [{ text: "Português - 葡萄牙语" }] },
        },
        {
          languageCode: "ps",
          languageName: { runs: [{ text: "پښتو - 普什图语" }] },
        },
        {
          languageCode: "ny",
          languageName: { runs: [{ text: "chiCheŵa - 齐切瓦语" }] },
        },
        {
          languageCode: "ja",
          languageName: { runs: [{ text: "日本語 - 日语" }] },
        },
        {
          languageCode: "sv",
          languageName: { runs: [{ text: "Svenska - 瑞典语" }] },
        },
        {
          languageCode: "sm",
          languageName: { runs: [{ text: "Gagana Samoa - 萨摩亚语" }] },
        },
        {
          languageCode: "sr",
          languageName: { runs: [{ text: "Српски језик - 塞尔维亚语" }] },
        },
        {
          languageCode: "si",
          languageName: { runs: [{ text: "සිංහල - 僧伽罗语" }] },
        },
        {
          languageCode: "sn",
          languageName: { runs: [{ text: "ChiShona - 绍纳语" }] },
        },
        {
          languageCode: "eo",
          languageName: { runs: [{ text: "Esperanto - 世界语" }] },
        },
        {
          languageCode: "sk",
          languageName: { runs: [{ text: "Slovenčina - 斯洛伐克语" }] },
        },
        {
          languageCode: "sl",
          languageName: { runs: [{ text: "Slovenščina - 斯洛文尼亚语" }] },
        },
        {
          languageCode: "sw",
          languageName: { runs: [{ text: "Kiswahili - 斯瓦希里语" }] },
        },
        {
          languageCode: "gd",
          languageName: { runs: [{ text: "Gàidhlig - 苏格兰盖尔语" }] },
        },
        {
          languageCode: "ceb",
          languageName: { runs: [{ text: "Cebuano - 宿务语" }] },
        },
        {
          languageCode: "so",
          languageName: { runs: [{ text: "Soomaaliga - 索马里语" }] },
        },
        {
          languageCode: "tg",
          languageName: { runs: [{ text: "тоҷикӣ - 塔吉克语" }] },
        },
        {
          languageCode: "te",
          languageName: { runs: [{ text: "తెలుగు - 泰卢固语" }] },
        },
        {
          languageCode: "ta",
          languageName: { runs: [{ text: "தமிழ் - 泰米尔语" }] },
        },
        {
          languageCode: "th",
          languageName: { runs: [{ text: "ไทย - 泰语" }] },
        },
        {
          languageCode: "ti",
          languageName: { runs: [{ text: "ትግርኛ - 提格利尼亚语" }] },
        },
        {
          languageCode: "tr",
          languageName: { runs: [{ text: "Türkçe - 土耳其语" }] },
        },
        {
          languageCode: "tk",
          languageName: { runs: [{ text: "Türkmen - 土库曼语" }] },
        },
        {
          languageCode: "cy",
          languageName: { runs: [{ text: "Cymraeg - 威尔士语" }] },
        },
        {
          languageCode: "ug",
          languageName: { runs: [{ text: "ئۇيغۇرچە - 维吾尔语" }] },
        },
        {
          languageCode: "und",
          languageName: { runs: [{ text: "Unknown - 未知语言" }] },
        },
        {
          languageCode: "ur",
          languageName: { runs: [{ text: "اردو - 乌尔都语" }] },
        },
        {
          languageCode: "uk",
          languageName: { runs: [{ text: "Українська - 乌克兰语" }] },
        },
        {
          languageCode: "uz",
          languageName: { runs: [{ text: "O‘zbek - 乌兹别克语" }] },
        },
        {
          languageCode: "es",
          languageName: { runs: [{ text: "Español - 西班牙语" }] },
        },
        {
          languageCode: "fy",
          languageName: { runs: [{ text: "Frysk - 西弗里西亚语" }] },
        },
        {
          languageCode: "iw",
          languageName: { runs: [{ text: "עברית - 希伯来语" }] },
        },
        {
          languageCode: "el",
          languageName: { runs: [{ text: "Ελληνικά - 希腊语" }] },
        },
        {
          languageCode: "haw",
          languageName: { runs: [{ text: "ʻŌlelo Hawaiʻi - 夏威夷语" }] },
        },
        {
          languageCode: "sd",
          languageName: { runs: [{ text: "سنڌي - 信德语" }] },
        },
        {
          languageCode: "hu",
          languageName: { runs: [{ text: "Magyar - 匈牙利语" }] },
        },
        {
          languageCode: "su",
          languageName: { runs: [{ text: "Basa Sunda - 巽他语" }] },
        },
        {
          languageCode: "hy",
          languageName: { runs: [{ text: "Հայերեն - 亚美尼亚语" }] },
        },
        {
          languageCode: "ig",
          languageName: { runs: [{ text: "Igbo - 伊博语" }] },
        },
        {
          languageCode: "it",
          languageName: { runs: [{ text: "Italiano - 意大利语" }] },
        },
        {
          languageCode: "yi",
          languageName: { runs: [{ text: "ייִדיש - 意第绪语" }] },
        },
        {
          languageCode: "hi",
          languageName: { runs: [{ text: "हिन्दी - 印地语" }] },
        },
        {
          languageCode: "id",
          languageName: { runs: [{ text: "Bahasa Indonesia - 印度尼西亚语" }] },
        },
        {
          languageCode: "en",
          languageName: { runs: [{ text: "English - 英语" }] },
        },
        {
          languageCode: "yo",
          languageName: { runs: [{ text: "Yorùbá - 约鲁巴语" }] },
        },
        {
          languageCode: "vi",
          languageName: { runs: [{ text: "Tiếng Việt - 越南语" }] },
        },
        {
          languageCode: "jv",
          languageName: { runs: [{ text: "Basa Jawa - 爪哇语" }] },
        },
        {
          languageCode: "zh-Hant",
          languageName: { runs: [{ text: "中文（繁體） - 中文（繁体）" }] },
        },
        {
          languageCode: "zh-Hans",
          languageName: { runs: [{ text: "中文（简体）" }] },
        },
        {
          languageCode: "zu",
          languageName: { runs: [{ text: "isiZulu - 祖鲁语" }] },
        },
        {
          languageCode: "kri",
          languageName: { runs: [{ text: "Krìì - 克里语" }] },
        },
      ],
    },
  },
  g = { Settings: o, Configs: u },
  c = (Database = {
    Default: Object.freeze({
      __proto__: null,
      Configs: i,
      Settings: r,
      default: l,
    }),
    YouTube: Object.freeze({
      __proto__: null,
      Configs: u,
      Settings: o,
      default: g,
    }),
  });
function m(e, n, r) {
  s("☑️ Set Environment Variables", "");
  let {
    Settings: i,
    Caches: l,
    Configs: o,
  } = (function (e, n, s) {
    let r = t.getItem(e, s),
      i = {};
    switch (typeof $argument) {
      case "string":
        let e = Object.fromEntries(
          $argument
            .split("&")
            .map((e) => e.split("=").map((e) => e.replace(/\"/g, "")))
        );
        for (let t in e) a.set(i, t, e[t]);
        break;
      case "object":
        for (let e in $argument) a.set(i, e, $argument[e]);
    }
    const l = {
      Settings: s?.Default?.Settings || {},
      Configs: s?.Default?.Configs || {},
      Caches: {},
    };
    Array.isArray(n) || (n = [n]);
    for (let e of n)
      (l.Settings = {
        ...l.Settings,
        ...s?.[e]?.Settings,
        ...i,
        ...r?.[e]?.Settings,
      }),
        (l.Configs = { ...l.Configs, ...s?.[e]?.Configs }),
        r?.[e]?.Caches &&
          "string" == typeof r?.[e]?.Caches &&
          (r[e].Caches = JSON.parse(r?.[e]?.Caches)),
        (l.Caches = { ...l.Caches, ...r?.[e]?.Caches });
    return (
      (function e(a, t) {
        for (var n in a) {
          var s = a[n];
          a[n] = "object" == typeof s && null !== s ? e(s, t) : t(n, s);
        }
        return a;
      })(
        l.Settings,
        (e, a) => (
          "true" === a || "false" === a
            ? (a = JSON.parse(a))
            : "string" == typeof a &&
              (a = a.includes(",") ? a.split(",").map((e) => o(e)) : o(a)),
          a
        )
      ),
      l
    );
    function o(e) {
      return e && !isNaN(e) && (e = parseInt(e, 10)), e;
    }
  })(e, n, r);
  return (
    Array.isArray(i?.Types) || (i.Types = i.Types ? [i.Types] : []),
    s(
      `✅ Set Environment Variables, Settings: ${typeof i}, Settings内容: ${JSON.stringify(
        i
      )}`,
      ""
    ),
    ("object" != typeof l?.Playlists || Array.isArray(l?.Playlists)) &&
      (l.Playlists = {}),
    (l.Playlists.Master = new Map(JSON.parse(l?.Playlists?.Master || "[]"))),
    (l.Playlists.Subtitle = new Map(
      JSON.parse(l?.Playlists?.Subtitle || "[]")
    )),
    "object" != typeof l?.Subtitles &&
      (l.Subtitles = new Map(JSON.parse(l?.Subtitles || "[]"))),
    ("object" != typeof l?.Metadatas || Array.isArray(l?.Metadatas)) &&
      (l.Metadatas = {}),
    "object" != typeof l?.Metadatas?.Tracks &&
      (l.Metadatas.Tracks = new Map(JSON.parse(l?.Metadatas?.Tracks || "[]"))),
    { Settings: i, Caches: l, Configs: o }
  );
}
function d(e) {
  let a = typeof e;
  if ("object" == a) {
    if (Array.isArray(e)) return "array";
    if (null === e) return "null";
  }
  return a;
}
let f =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(
      ""
    ),
  h = [];
for (let e = 0; e < f.length; e++) h[f[e].charCodeAt(0)] = e;
var p, N;
function b() {
  let e = 0,
    a = 0;
  for (let t = 0; t < 28; t += 7) {
    let n = this.buf[this.pos++];
    if (((e |= (127 & n) << t), !(128 & n))) return this.assertBounds(), [e, a];
  }
  let t = this.buf[this.pos++];
  if (((e |= (15 & t) << 28), (a = (112 & t) >> 4), !(128 & t)))
    return this.assertBounds(), [e, a];
  for (let t = 3; t <= 31; t += 7) {
    let n = this.buf[this.pos++];
    if (((a |= (127 & n) << t), !(128 & n))) return this.assertBounds(), [e, a];
  }
  throw new Error("invalid varint");
}
function y(e, a, t) {
  for (let n = 0; n < 28; n += 7) {
    const s = e >>> n,
      r = !(s >>> 7 == 0 && 0 == a),
      i = 255 & (r ? 128 | s : s);
    if ((t.push(i), !r)) return;
  }
  const n = ((e >>> 28) & 15) | ((7 & a) << 4),
    s = !!(a >> 3);
  if ((t.push(255 & (s ? 128 | n : n)), s)) {
    for (let e = 3; e < 31; e += 7) {
      const n = a >>> e,
        s = !(n >>> 7 == 0),
        r = 255 & (s ? 128 | n : n);
      if ((t.push(r), !s)) return;
    }
    t.push((a >>> 31) & 1);
  }
}
(h["-".charCodeAt(0)] = f.indexOf("+")),
  (h["_".charCodeAt(0)] = f.indexOf("/")),
  (function (e) {
    (e.symbol = Symbol.for("protobuf-ts/unknown")),
      (e.onRead = (t, n, s, r, i) => {
        (a(n) ? n[e.symbol] : (n[e.symbol] = [])).push({
          no: s,
          wireType: r,
          data: i,
        });
      }),
      (e.onWrite = (a, t, n) => {
        for (let { no: a, wireType: s, data: r } of e.list(t))
          n.tag(a, s).raw(r);
      }),
      (e.list = (t, n) => {
        if (a(t)) {
          let a = t[e.symbol];
          return n ? a.filter((e) => e.no == n) : a;
        }
        return [];
      }),
      (e.last = (a, t) => e.list(a, t).slice(-1)[0]);
    const a = (a) => a && Array.isArray(a[e.symbol]);
  })(p || (p = {})),
  (function (e) {
    (e[(e.Varint = 0)] = "Varint"),
      (e[(e.Bit64 = 1)] = "Bit64"),
      (e[(e.LengthDelimited = 2)] = "LengthDelimited"),
      (e[(e.StartGroup = 3)] = "StartGroup"),
      (e[(e.EndGroup = 4)] = "EndGroup"),
      (e[(e.Bit32 = 5)] = "Bit32");
  })(N || (N = {}));
const T = 4294967296;
function x(e) {
  let a = "-" == e[0];
  a && (e = e.slice(1));
  const t = 1e6;
  let n = 0,
    s = 0;
  function r(a, r) {
    const i = Number(e.slice(a, r));
    (s *= t), (n = n * t + i), n >= T && ((s += (n / T) | 0), (n %= T));
  }
  return r(-24, -18), r(-18, -12), r(-12, -6), r(-6), [a, n, s];
}
function C(e, a) {
  if (a >>> 0 <= 2097151) return "" + (T * a + (e >>> 0));
  let t = (((e >>> 24) | (a << 8)) >>> 0) & 16777215,
    n = (a >> 16) & 65535,
    s = (16777215 & e) + 6777216 * t + 6710656 * n,
    r = t + 8147497 * n,
    i = 2 * n,
    l = 1e7;
  function o(e, a) {
    let t = e ? String(e) : "";
    return a ? "0000000".slice(t.length) + t : t;
  }
  return (
    s >= l && ((r += Math.floor(s / l)), (s %= l)),
    r >= l && ((i += Math.floor(r / l)), (r %= l)),
    o(i, 0) + o(r, i) + o(s, 1)
  );
}
function k(e, a) {
  if (e >= 0) {
    for (; e > 127; ) a.push((127 & e) | 128), (e >>>= 7);
    a.push(e);
  } else {
    for (let t = 0; t < 9; t++) a.push((127 & e) | 128), (e >>= 7);
    a.push(1);
  }
}
function w() {
  let e = this.buf[this.pos++],
    a = 127 & e;
  if (!(128 & e)) return this.assertBounds(), a;
  if (((e = this.buf[this.pos++]), (a |= (127 & e) << 7), !(128 & e)))
    return this.assertBounds(), a;
  if (((e = this.buf[this.pos++]), (a |= (127 & e) << 14), !(128 & e)))
    return this.assertBounds(), a;
  if (((e = this.buf[this.pos++]), (a |= (127 & e) << 21), !(128 & e)))
    return this.assertBounds(), a;
  (e = this.buf[this.pos++]), (a |= (15 & e) << 28);
  for (let a = 5; 128 & e && a < 10; a++) e = this.buf[this.pos++];
  if (128 & e) throw new Error("invalid varint");
  return this.assertBounds(), a >>> 0;
}
let S;
function I(e) {
  if (!e)
    throw new Error(
      "BigInt unavailable, see https://github.com/timostamm/protobuf-ts/blob/v1.0.8/MANUAL.md#bigint-support"
    );
}
!(function () {
  const e = new DataView(new ArrayBuffer(8)),
    a =
      void 0 !== globalThis.BigInt &&
      "function" == typeof e.getBigInt64 &&
      "function" == typeof e.getBigUint64 &&
      "function" == typeof e.setBigInt64 &&
      "function" == typeof e.setBigUint64;
  S = a
    ? {
        MIN: BigInt("-9223372036854775808"),
        MAX: BigInt("9223372036854775807"),
        UMIN: BigInt("0"),
        UMAX: BigInt("18446744073709551615"),
        C: BigInt,
        V: e,
      }
    : void 0;
})();
const v = /^-?[0-9]+$/,
  E = 4294967296,
  O = 2147483648;
class B {
  constructor(e, a) {
    (this.lo = 0 | e), (this.hi = 0 | a);
  }
  isZero() {
    return 0 == this.lo && 0 == this.hi;
  }
  toNumber() {
    let e = this.hi * E + (this.lo >>> 0);
    if (!Number.isSafeInteger(e))
      throw new Error("cannot convert to safe number");
    return e;
  }
}
class A extends B {
  static from(e) {
    if (S)
      switch (typeof e) {
        case "string":
          if ("0" == e) return this.ZERO;
          if ("" == e) throw new Error("string is no integer");
          e = S.C(e);
        case "number":
          if (0 === e) return this.ZERO;
          e = S.C(e);
        case "bigint":
          if (!e) return this.ZERO;
          if (e < S.UMIN) throw new Error("signed value for ulong");
          if (e > S.UMAX) throw new Error("ulong too large");
          return (
            S.V.setBigUint64(0, e, !0),
            new A(S.V.getInt32(0, !0), S.V.getInt32(4, !0))
          );
      }
    else
      switch (typeof e) {
        case "string":
          if ("0" == e) return this.ZERO;
          if (((e = e.trim()), !v.test(e)))
            throw new Error("string is no integer");
          let [a, t, n] = x(e);
          if (a) throw new Error("signed value for ulong");
          return new A(t, n);
        case "number":
          if (0 == e) return this.ZERO;
          if (!Number.isSafeInteger(e)) throw new Error("number is no integer");
          if (e < 0) throw new Error("signed value for ulong");
          return new A(e, e / E);
      }
    throw new Error("unknown value " + typeof e);
  }
  toString() {
    return S ? this.toBigInt().toString() : C(this.lo, this.hi);
  }
  toBigInt() {
    return (
      I(S),
      S.V.setInt32(0, this.lo, !0),
      S.V.setInt32(4, this.hi, !0),
      S.V.getBigUint64(0, !0)
    );
  }
}
A.ZERO = new A(0, 0);
class L extends B {
  static from(e) {
    if (S)
      switch (typeof e) {
        case "string":
          if ("0" == e) return this.ZERO;
          if ("" == e) throw new Error("string is no integer");
          e = S.C(e);
        case "number":
          if (0 === e) return this.ZERO;
          e = S.C(e);
        case "bigint":
          if (!e) return this.ZERO;
          if (e < S.MIN) throw new Error("signed long too small");
          if (e > S.MAX) throw new Error("signed long too large");
          return (
            S.V.setBigInt64(0, e, !0),
            new L(S.V.getInt32(0, !0), S.V.getInt32(4, !0))
          );
      }
    else
      switch (typeof e) {
        case "string":
          if ("0" == e) return this.ZERO;
          if (((e = e.trim()), !v.test(e)))
            throw new Error("string is no integer");
          let [a, t, n] = x(e);
          if (a) {
            if (n > O || (n == O && 0 != t))
              throw new Error("signed long too small");
          } else if (n >= O) throw new Error("signed long too large");
          let s = new L(t, n);
          return a ? s.negate() : s;
        case "number":
          if (0 == e) return this.ZERO;
          if (!Number.isSafeInteger(e)) throw new Error("number is no integer");
          return e > 0 ? new L(e, e / E) : new L(-e, -e / E).negate();
      }
    throw new Error("unknown value " + typeof e);
  }
  isNegative() {
    return !!(this.hi & O);
  }
  negate() {
    let e = ~this.hi,
      a = this.lo;
    return a ? (a = 1 + ~a) : (e += 1), new L(a, e);
  }
  toString() {
    if (S) return this.toBigInt().toString();
    if (this.isNegative()) {
      let e = this.negate();
      return "-" + C(e.lo, e.hi);
    }
    return C(this.lo, this.hi);
  }
  toBigInt() {
    return (
      I(S),
      S.V.setInt32(0, this.lo, !0),
      S.V.setInt32(4, this.hi, !0),
      S.V.getBigInt64(0, !0)
    );
  }
}
L.ZERO = new L(0, 0);
const D = { readUnknownField: !0, readerFactory: (e) => new U(e) };
class U {
  constructor(e, a) {
    (this.varint64 = b),
      (this.uint32 = w),
      (this.buf = e),
      (this.len = e.length),
      (this.pos = 0),
      (this.view = new DataView(e.buffer, e.byteOffset, e.byteLength)),
      (this.textDecoder =
        null != a ? a : new TextDecoder("utf-8", { fatal: !0, ignoreBOM: !0 }));
  }
  tag() {
    let e = this.uint32(),
      a = e >>> 3,
      t = 7 & e;
    if (a <= 0 || t < 0 || t > 5)
      throw new Error("illegal tag: field no " + a + " wire type " + t);
    return [a, t];
  }
  skip(e) {
    let a = this.pos;
    switch (e) {
      case N.Varint:
        for (; 128 & this.buf[this.pos++]; );
        break;
      case N.Bit64:
        this.pos += 4;
      case N.Bit32:
        this.pos += 4;
        break;
      case N.LengthDelimited:
        let a = this.uint32();
        this.pos += a;
        break;
      case N.StartGroup:
        let t;
        for (; (t = this.tag()[1]) !== N.EndGroup; ) this.skip(t);
        break;
      default:
        throw new Error("cant skip wire type " + e);
    }
    return this.assertBounds(), this.buf.subarray(a, this.pos);
  }
  assertBounds() {
    if (this.pos > this.len) throw new RangeError("premature EOF");
  }
  int32() {
    return 0 | this.uint32();
  }
  sint32() {
    let e = this.uint32();
    return (e >>> 1) ^ -(1 & e);
  }
  int64() {
    return new L(...this.varint64());
  }
  uint64() {
    return new A(...this.varint64());
  }
  sint64() {
    let [e, a] = this.varint64(),
      t = -(1 & e);
    return (
      (e = ((e >>> 1) | ((1 & a) << 31)) ^ t), (a = (a >>> 1) ^ t), new L(e, a)
    );
  }
  bool() {
    let [e, a] = this.varint64();
    return 0 !== e || 0 !== a;
  }
  fixed32() {
    return this.view.getUint32((this.pos += 4) - 4, !0);
  }
  sfixed32() {
    return this.view.getInt32((this.pos += 4) - 4, !0);
  }
  fixed64() {
    return new A(this.sfixed32(), this.sfixed32());
  }
  sfixed64() {
    return new L(this.sfixed32(), this.sfixed32());
  }
  float() {
    return this.view.getFloat32((this.pos += 4) - 4, !0);
  }
  double() {
    return this.view.getFloat64((this.pos += 8) - 8, !0);
  }
  bytes() {
    let e = this.uint32(),
      a = this.pos;
    return (this.pos += e), this.assertBounds(), this.buf.subarray(a, a + e);
  }
  string() {
    return this.textDecoder.decode(this.bytes());
  }
}
function F(e, a) {
  if (!e) throw new Error(a);
}
function $(e) {
  if ("number" != typeof e) throw new Error("invalid int 32: " + typeof e);
  if (!Number.isInteger(e) || e > 2147483647 || e < -2147483648)
    throw new Error("invalid int 32: " + e);
}
function V(e) {
  if ("number" != typeof e) throw new Error("invalid uint 32: " + typeof e);
  if (!Number.isInteger(e) || e > 4294967295 || e < 0)
    throw new Error("invalid uint 32: " + e);
}
function j(e) {
  if ("number" != typeof e) throw new Error("invalid float 32: " + typeof e);
  if (
    Number.isFinite(e) &&
    (e > 34028234663852886e22 || e < -34028234663852886e22)
  )
    throw new Error("invalid float 32: " + e);
}
const P = { writeUnknownFields: !0, writerFactory: () => new R() };
class R {
  constructor(e) {
    (this.stack = []),
      (this.textEncoder = null != e ? e : new TextEncoder()),
      (this.chunks = []),
      (this.buf = []);
  }
  finish() {
    this.chunks.push(new Uint8Array(this.buf));
    let e = 0;
    for (let a = 0; a < this.chunks.length; a++) e += this.chunks[a].length;
    let a = new Uint8Array(e),
      t = 0;
    for (let e = 0; e < this.chunks.length; e++)
      a.set(this.chunks[e], t), (t += this.chunks[e].length);
    return (this.chunks = []), a;
  }
  fork() {
    return (
      this.stack.push({ chunks: this.chunks, buf: this.buf }),
      (this.chunks = []),
      (this.buf = []),
      this
    );
  }
  join() {
    let e = this.finish(),
      a = this.stack.pop();
    if (!a) throw new Error("invalid state, fork stack empty");
    return (
      (this.chunks = a.chunks),
      (this.buf = a.buf),
      this.uint32(e.byteLength),
      this.raw(e)
    );
  }
  tag(e, a) {
    return this.uint32(((e << 3) | a) >>> 0);
  }
  raw(e) {
    return (
      this.buf.length &&
        (this.chunks.push(new Uint8Array(this.buf)), (this.buf = [])),
      this.chunks.push(e),
      this
    );
  }
  uint32(e) {
    for (V(e); e > 127; ) this.buf.push((127 & e) | 128), (e >>>= 7);
    return this.buf.push(e), this;
  }
  int32(e) {
    return $(e), k(e, this.buf), this;
  }
  bool(e) {
    return this.buf.push(e ? 1 : 0), this;
  }
  bytes(e) {
    return this.uint32(e.byteLength), this.raw(e);
  }
  string(e) {
    let a = this.textEncoder.encode(e);
    return this.uint32(a.byteLength), this.raw(a);
  }
  float(e) {
    j(e);
    let a = new Uint8Array(4);
    return new DataView(a.buffer).setFloat32(0, e, !0), this.raw(a);
  }
  double(e) {
    let a = new Uint8Array(8);
    return new DataView(a.buffer).setFloat64(0, e, !0), this.raw(a);
  }
  fixed32(e) {
    V(e);
    let a = new Uint8Array(4);
    return new DataView(a.buffer).setUint32(0, e, !0), this.raw(a);
  }
  sfixed32(e) {
    $(e);
    let a = new Uint8Array(4);
    return new DataView(a.buffer).setInt32(0, e, !0), this.raw(a);
  }
  sint32(e) {
    return $(e), k((e = ((e << 1) ^ (e >> 31)) >>> 0), this.buf), this;
  }
  sfixed64(e) {
    let a = new Uint8Array(8),
      t = new DataView(a.buffer),
      n = L.from(e);
    return t.setInt32(0, n.lo, !0), t.setInt32(4, n.hi, !0), this.raw(a);
  }
  fixed64(e) {
    let a = new Uint8Array(8),
      t = new DataView(a.buffer),
      n = A.from(e);
    return t.setInt32(0, n.lo, !0), t.setInt32(4, n.hi, !0), this.raw(a);
  }
  int64(e) {
    let a = L.from(e);
    return y(a.lo, a.hi, this.buf), this;
  }
  sint64(e) {
    let a = L.from(e),
      t = a.hi >> 31;
    return (
      y((a.lo << 1) ^ t, ((a.hi << 1) | (a.lo >>> 31)) ^ t, this.buf), this
    );
  }
  uint64(e) {
    let a = A.from(e);
    return y(a.lo, a.hi, this.buf), this;
  }
}
const K = {
    emitDefaultValues: !1,
    enumAsInteger: !1,
    useProtoFieldName: !1,
    prettySpaces: 0,
  },
  M = { ignoreUnknownFields: !1 };
const X = Symbol.for("protobuf-ts/message-type");
function J(e) {
  let a = !1;
  const t = [];
  for (let n = 0; n < e.length; n++) {
    let s = e.charAt(n);
    "_" == s
      ? (a = !0)
      : /\d/.test(s)
      ? (t.push(s), (a = !0))
      : a
      ? (t.push(s.toUpperCase()), (a = !1))
      : 0 == n
      ? t.push(s.toLowerCase())
      : t.push(s);
  }
  return t.join("");
}
var G, q, Z;
function H(e) {
  var a, t, n, s;
  return (
    (e.localName = null !== (a = e.localName) && void 0 !== a ? a : J(e.name)),
    (e.jsonName = null !== (t = e.jsonName) && void 0 !== t ? t : J(e.name)),
    (e.repeat = null !== (n = e.repeat) && void 0 !== n ? n : Z.NO),
    (e.opt =
      null !== (s = e.opt) && void 0 !== s
        ? s
        : !e.repeat && !e.oneof && "message" == e.kind),
    e
  );
}
function z(e) {
  if ("object" != typeof e || null === e || !e.hasOwnProperty("oneofKind"))
    return !1;
  switch (typeof e.oneofKind) {
    case "string":
      return void 0 !== e[e.oneofKind] && 2 == Object.keys(e).length;
    case "undefined":
      return 1 == Object.keys(e).length;
    default:
      return !1;
  }
}
!(function (e) {
  (e[(e.DOUBLE = 1)] = "DOUBLE"),
    (e[(e.FLOAT = 2)] = "FLOAT"),
    (e[(e.INT64 = 3)] = "INT64"),
    (e[(e.UINT64 = 4)] = "UINT64"),
    (e[(e.INT32 = 5)] = "INT32"),
    (e[(e.FIXED64 = 6)] = "FIXED64"),
    (e[(e.FIXED32 = 7)] = "FIXED32"),
    (e[(e.BOOL = 8)] = "BOOL"),
    (e[(e.STRING = 9)] = "STRING"),
    (e[(e.BYTES = 12)] = "BYTES"),
    (e[(e.UINT32 = 13)] = "UINT32"),
    (e[(e.SFIXED32 = 15)] = "SFIXED32"),
    (e[(e.SFIXED64 = 16)] = "SFIXED64"),
    (e[(e.SINT32 = 17)] = "SINT32"),
    (e[(e.SINT64 = 18)] = "SINT64");
})(G || (G = {})),
  (function (e) {
    (e[(e.BIGINT = 0)] = "BIGINT"),
      (e[(e.STRING = 1)] = "STRING"),
      (e[(e.NUMBER = 2)] = "NUMBER");
  })(q || (q = {})),
  (function (e) {
    (e[(e.NO = 0)] = "NO"),
      (e[(e.PACKED = 1)] = "PACKED"),
      (e[(e.UNPACKED = 2)] = "UNPACKED");
  })(Z || (Z = {}));
class Y {
  constructor(e) {
    var a;
    this.fields = null !== (a = e.fields) && void 0 !== a ? a : [];
  }
  prepare() {
    if (this.data) return;
    const e = [],
      a = [],
      t = [];
    for (let n of this.fields)
      if (n.oneof)
        t.includes(n.oneof) ||
          (t.push(n.oneof), e.push(n.oneof), a.push(n.oneof));
      else
        switch ((a.push(n.localName), n.kind)) {
          case "scalar":
          case "enum":
            (n.opt && !n.repeat) || e.push(n.localName);
            break;
          case "message":
            n.repeat && e.push(n.localName);
            break;
          case "map":
            e.push(n.localName);
        }
    this.data = { req: e, known: a, oneofs: Object.values(t) };
  }
  is(e, a, t = !1) {
    if (a < 0) return !0;
    if (null == e || "object" != typeof e) return !1;
    this.prepare();
    let n = Object.keys(e),
      s = this.data;
    if (n.length < s.req.length || s.req.some((e) => !n.includes(e))) return !1;
    if (!t && n.some((e) => !s.known.includes(e))) return !1;
    if (a < 1) return !0;
    for (const n of s.oneofs) {
      const s = e[n];
      if (!z(s)) return !1;
      if (void 0 === s.oneofKind) continue;
      const r = this.fields.find((e) => e.localName === s.oneofKind);
      if (!r) return !1;
      if (!this.field(s[s.oneofKind], r, t, a)) return !1;
    }
    for (const n of this.fields)
      if (void 0 === n.oneof && !this.field(e[n.localName], n, t, a)) return !1;
    return !0;
  }
  field(e, a, t, n) {
    let s = a.repeat;
    switch (a.kind) {
      case "scalar":
        return void 0 === e
          ? a.opt
          : s
          ? this.scalars(e, a.T, n, a.L)
          : this.scalar(e, a.T, a.L);
      case "enum":
        return void 0 === e
          ? a.opt
          : s
          ? this.scalars(e, G.INT32, n)
          : this.scalar(e, G.INT32);
      case "message":
        return (
          void 0 === e ||
          (s ? this.messages(e, a.T(), t, n) : this.message(e, a.T(), t, n))
        );
      case "map":
        if ("object" != typeof e || null === e) return !1;
        if (n < 2) return !0;
        if (!this.mapKeys(e, a.K, n)) return !1;
        switch (a.V.kind) {
          case "scalar":
            return this.scalars(Object.values(e), a.V.T, n, a.V.L);
          case "enum":
            return this.scalars(Object.values(e), G.INT32, n);
          case "message":
            return this.messages(Object.values(e), a.V.T(), t, n);
        }
    }
    return !0;
  }
  message(e, a, t, n) {
    return t ? a.isAssignable(e, n) : a.is(e, n);
  }
  messages(e, a, t, n) {
    if (!Array.isArray(e)) return !1;
    if (n < 2) return !0;
    if (t) {
      for (let t = 0; t < e.length && t < n; t++)
        if (!a.isAssignable(e[t], n - 1)) return !1;
    } else
      for (let t = 0; t < e.length && t < n; t++)
        if (!a.is(e[t], n - 1)) return !1;
    return !0;
  }
  scalar(e, a, t) {
    let n = typeof e;
    switch (a) {
      case G.UINT64:
      case G.FIXED64:
      case G.INT64:
      case G.SFIXED64:
      case G.SINT64:
        switch (t) {
          case q.BIGINT:
            return "bigint" == n;
          case q.NUMBER:
            return "number" == n && !isNaN(e);
          default:
            return "string" == n;
        }
      case G.BOOL:
        return "boolean" == n;
      case G.STRING:
        return "string" == n;
      case G.BYTES:
        return e instanceof Uint8Array;
      case G.DOUBLE:
      case G.FLOAT:
        return "number" == n && !isNaN(e);
      default:
        return "number" == n && Number.isInteger(e);
    }
  }
  scalars(e, a, t, n) {
    if (!Array.isArray(e)) return !1;
    if (t < 2) return !0;
    if (Array.isArray(e))
      for (let s = 0; s < e.length && s < t; s++)
        if (!this.scalar(e[s], a, n)) return !1;
    return !0;
  }
  mapKeys(e, a, t) {
    let n = Object.keys(e);
    switch (a) {
      case G.INT32:
      case G.FIXED32:
      case G.SFIXED32:
      case G.SINT32:
      case G.UINT32:
        return this.scalars(
          n.slice(0, t).map((e) => parseInt(e)),
          a,
          t
        );
      case G.BOOL:
        return this.scalars(
          n.slice(0, t).map((e) => "true" == e || ("false" != e && e)),
          a,
          t
        );
      default:
        return this.scalars(n, a, t, q.STRING);
    }
  }
}
function W(e, a) {
  switch (a) {
    case q.BIGINT:
      return e.toBigInt();
    case q.NUMBER:
      return e.toNumber();
    default:
      return e.toString();
  }
}
class _ {
  constructor(e) {
    this.info = e;
  }
  prepare() {
    var e;
    if (void 0 === this.fMap) {
      this.fMap = {};
      const a = null !== (e = this.info.fields) && void 0 !== e ? e : [];
      for (const e of a)
        (this.fMap[e.name] = e),
          (this.fMap[e.jsonName] = e),
          (this.fMap[e.localName] = e);
    }
  }
  assert(e, a, t) {
    if (!e) {
      let e = d(t);
      throw (
        (("number" != e && "boolean" != e) || (e = t.toString()),
        new Error(`Cannot parse JSON ${e} for ${this.info.typeName}#${a}`))
      );
    }
  }
  read(e, a, t) {
    this.prepare();
    const n = [];
    for (const [r, i] of Object.entries(e)) {
      const e = this.fMap[r];
      if (!e) {
        if (!t.ignoreUnknownFields)
          throw new Error(
            `Found unknown field while reading ${this.info.typeName} from JSON format. JSON key: ${r}`
          );
        continue;
      }
      const l = e.localName;
      let o;
      if (e.oneof) {
        if (
          null === i &&
          ("enum" !== e.kind || "google.protobuf.NullValue" !== e.T()[0])
        )
          continue;
        if (n.includes(e.oneof))
          throw new Error(
            `Multiple members of the oneof group "${e.oneof}" of ${this.info.typeName} are present in JSON.`
          );
        n.push(e.oneof), (o = a[e.oneof] = { oneofKind: l });
      } else o = a;
      if ("map" == e.kind) {
        if (null === i) continue;
        this.assert(
          null !== (s = i) && "object" == typeof s && !Array.isArray(s),
          e.name,
          i
        );
        const a = o[l];
        for (const [n, s] of Object.entries(i)) {
          let r;
          switch (
            (this.assert(null !== s, e.name + " map value", null), e.V.kind)
          ) {
            case "message":
              r = e.V.T().internalJsonRead(s, t);
              break;
            case "enum":
              if (
                ((r = this.enum(e.V.T(), s, e.name, t.ignoreUnknownFields)),
                !1 === r)
              )
                continue;
              break;
            case "scalar":
              r = this.scalar(s, e.V.T, e.V.L, e.name);
          }
          this.assert(void 0 !== r, e.name + " map value", s);
          let i = n;
          e.K == G.BOOL && (i = "true" == i || ("false" != i && i)),
            (i = this.scalar(i, e.K, q.STRING, e.name).toString()),
            (a[i] = r);
        }
      } else if (e.repeat) {
        if (null === i) continue;
        this.assert(Array.isArray(i), e.name, i);
        const a = o[l];
        for (const n of i) {
          let s;
          switch ((this.assert(null !== n, e.name, null), e.kind)) {
            case "message":
              s = e.T().internalJsonRead(n, t);
              break;
            case "enum":
              if (
                ((s = this.enum(e.T(), n, e.name, t.ignoreUnknownFields)),
                !1 === s)
              )
                continue;
              break;
            case "scalar":
              s = this.scalar(n, e.T, e.L, e.name);
          }
          this.assert(void 0 !== s, e.name, i), a.push(s);
        }
      } else
        switch (e.kind) {
          case "message":
            if (null === i && "google.protobuf.Value" != e.T().typeName) {
              this.assert(void 0 === e.oneof, e.name + " (oneof member)", null);
              continue;
            }
            o[l] = e.T().internalJsonRead(i, t, o[l]);
            break;
          case "enum":
            let a = this.enum(e.T(), i, e.name, t.ignoreUnknownFields);
            if (!1 === a) continue;
            o[l] = a;
            break;
          case "scalar":
            o[l] = this.scalar(i, e.T, e.L, e.name);
        }
    }
    var s;
  }
  enum(e, a, t, n) {
    if (
      ("google.protobuf.NullValue" == e[0] &&
        F(
          null === a || "NULL_VALUE" === a,
          `Unable to parse field ${this.info.typeName}#${t}, enum ${e[0]} only accepts null.`
        ),
      null === a)
    )
      return 0;
    switch (typeof a) {
      case "number":
        return (
          F(
            Number.isInteger(a),
            `Unable to parse field ${this.info.typeName}#${t}, enum can only be integral number, got ${a}.`
          ),
          a
        );
      case "string":
        let s = a;
        e[2] &&
          a.substring(0, e[2].length) === e[2] &&
          (s = a.substring(e[2].length));
        let r = e[1][s];
        return (
          (void 0 !== r || !n) &&
          (F(
            "number" == typeof r,
            `Unable to parse field ${this.info.typeName}#${t}, enum ${e[0]} has no value for "${a}".`
          ),
          r)
        );
    }
    F(
      !1,
      `Unable to parse field ${
        this.info.typeName
      }#${t}, cannot parse enum value from ${typeof a}".`
    );
  }
  scalar(e, a, t, n) {
    let s;
    try {
      switch (a) {
        case G.DOUBLE:
        case G.FLOAT:
          if (null === e) return 0;
          if ("NaN" === e) return Number.NaN;
          if ("Infinity" === e) return Number.POSITIVE_INFINITY;
          if ("-Infinity" === e) return Number.NEGATIVE_INFINITY;
          if ("" === e) {
            s = "empty string";
            break;
          }
          if ("string" == typeof e && e.trim().length !== e.length) {
            s = "extra whitespace";
            break;
          }
          if ("string" != typeof e && "number" != typeof e) break;
          let n = Number(e);
          if (Number.isNaN(n)) {
            s = "not a number";
            break;
          }
          if (!Number.isFinite(n)) {
            s = "too large or small";
            break;
          }
          return a == G.FLOAT && j(n), n;
        case G.INT32:
        case G.FIXED32:
        case G.SFIXED32:
        case G.SINT32:
        case G.UINT32:
          if (null === e) return 0;
          let r;
          if (
            ("number" == typeof e
              ? (r = e)
              : "" === e
              ? (s = "empty string")
              : "string" == typeof e &&
                (e.trim().length !== e.length
                  ? (s = "extra whitespace")
                  : (r = Number(e))),
            void 0 === r)
          )
            break;
          return a == G.UINT32 ? V(r) : $(r), r;
        case G.INT64:
        case G.SFIXED64:
        case G.SINT64:
          if (null === e) return W(L.ZERO, t);
          if ("number" != typeof e && "string" != typeof e) break;
          return W(L.from(e), t);
        case G.FIXED64:
        case G.UINT64:
          if (null === e) return W(A.ZERO, t);
          if ("number" != typeof e && "string" != typeof e) break;
          return W(A.from(e), t);
        case G.BOOL:
          if (null === e) return !1;
          if ("boolean" != typeof e) break;
          return e;
        case G.STRING:
          if (null === e) return "";
          if ("string" != typeof e) {
            s = "extra whitespace";
            break;
          }
          try {
            encodeURIComponent(e);
          } catch (s) {
            s = "invalid UTF8";
            break;
          }
          return e;
        case G.BYTES:
          if (null === e || "" === e) return new Uint8Array(0);
          if ("string" != typeof e) break;
          return (function (e) {
            let a = (3 * e.length) / 4;
            "=" == e[e.length - 2]
              ? (a -= 2)
              : "=" == e[e.length - 1] && (a -= 1);
            let t,
              n = new Uint8Array(a),
              s = 0,
              r = 0,
              i = 0;
            for (let a = 0; a < e.length; a++) {
              if (((t = h[e.charCodeAt(a)]), void 0 === t))
                switch (e[a]) {
                  case "=":
                    r = 0;
                  case "\n":
                  case "\r":
                  case "\t":
                  case " ":
                    continue;
                  default:
                    throw Error("invalid base64 string.");
                }
              switch (r) {
                case 0:
                  (i = t), (r = 1);
                  break;
                case 1:
                  (n[s++] = (i << 2) | ((48 & t) >> 4)), (i = t), (r = 2);
                  break;
                case 2:
                  (n[s++] = ((15 & i) << 4) | ((60 & t) >> 2)),
                    (i = t),
                    (r = 3);
                  break;
                case 3:
                  (n[s++] = ((3 & i) << 6) | t), (r = 0);
              }
            }
            if (1 == r) throw Error("invalid base64 string.");
            return n.subarray(0, s);
          })(e);
      }
    } catch (e) {
      s = e.message;
    }
    this.assert(!1, n + (s ? " - " + s : ""), e);
  }
}
class Q {
  constructor(e) {
    var a;
    this.fields = null !== (a = e.fields) && void 0 !== a ? a : [];
  }
  write(e, a) {
    const t = {},
      n = e;
    for (const e of this.fields) {
      if (!e.oneof) {
        let s = this.field(e, n[e.localName], a);
        void 0 !== s && (t[a.useProtoFieldName ? e.name : e.jsonName] = s);
        continue;
      }
      const s = n[e.oneof];
      if (s.oneofKind !== e.localName) continue;
      const r =
        "scalar" == e.kind || "enum" == e.kind
          ? Object.assign(Object.assign({}, a), { emitDefaultValues: !0 })
          : a;
      let i = this.field(e, s[e.localName], r);
      F(void 0 !== i), (t[a.useProtoFieldName ? e.name : e.jsonName] = i);
    }
    return t;
  }
  field(e, a, t) {
    let n;
    if ("map" == e.kind) {
      F("object" == typeof a && null !== a);
      const s = {};
      switch (e.V.kind) {
        case "scalar":
          for (const [t, n] of Object.entries(a)) {
            const a = this.scalar(e.V.T, n, e.name, !1, !0);
            F(void 0 !== a), (s[t.toString()] = a);
          }
          break;
        case "message":
          const n = e.V.T();
          for (const [r, i] of Object.entries(a)) {
            const a = this.message(n, i, e.name, t);
            F(void 0 !== a), (s[r.toString()] = a);
          }
          break;
        case "enum":
          const r = e.V.T();
          for (const [n, i] of Object.entries(a)) {
            F(void 0 === i || "number" == typeof i);
            const a = this.enum(r, i, e.name, !1, !0, t.enumAsInteger);
            F(void 0 !== a), (s[n.toString()] = a);
          }
      }
      (t.emitDefaultValues || Object.keys(s).length > 0) && (n = s);
    } else if (e.repeat) {
      F(Array.isArray(a));
      const s = [];
      switch (e.kind) {
        case "scalar":
          for (let t = 0; t < a.length; t++) {
            const n = this.scalar(e.T, a[t], e.name, e.opt, !0);
            F(void 0 !== n), s.push(n);
          }
          break;
        case "enum":
          const n = e.T();
          for (let r = 0; r < a.length; r++) {
            F(void 0 === a[r] || "number" == typeof a[r]);
            const i = this.enum(n, a[r], e.name, e.opt, !0, t.enumAsInteger);
            F(void 0 !== i), s.push(i);
          }
          break;
        case "message":
          const r = e.T();
          for (let n = 0; n < a.length; n++) {
            const i = this.message(r, a[n], e.name, t);
            F(void 0 !== i), s.push(i);
          }
      }
      (t.emitDefaultValues || s.length > 0 || t.emitDefaultValues) && (n = s);
    } else
      switch (e.kind) {
        case "scalar":
          n = this.scalar(e.T, a, e.name, e.opt, t.emitDefaultValues);
          break;
        case "enum":
          n = this.enum(
            e.T(),
            a,
            e.name,
            e.opt,
            t.emitDefaultValues,
            t.enumAsInteger
          );
          break;
        case "message":
          n = this.message(e.T(), a, e.name, t);
      }
    return n;
  }
  enum(e, a, t, n, s, r) {
    if ("google.protobuf.NullValue" == e[0]) return s || n ? null : void 0;
    if (void 0 !== a) {
      if (0 !== a || s || n)
        return (
          F("number" == typeof a),
          F(Number.isInteger(a)),
          r || !e[1].hasOwnProperty(a) ? a : e[2] ? e[2] + e[1][a] : e[1][a]
        );
    } else F(n);
  }
  message(e, a, t, n) {
    return void 0 === a
      ? n.emitDefaultValues
        ? null
        : void 0
      : e.internalJsonWrite(a, n);
  }
  scalar(e, a, t, n, s) {
    if (void 0 === a) return void F(n);
    const r = s || n;
    switch (e) {
      case G.INT32:
      case G.SFIXED32:
      case G.SINT32:
        return 0 === a ? (r ? 0 : void 0) : ($(a), a);
      case G.FIXED32:
      case G.UINT32:
        return 0 === a ? (r ? 0 : void 0) : (V(a), a);
      case G.FLOAT:
        j(a);
      case G.DOUBLE:
        return 0 === a
          ? r
            ? 0
            : void 0
          : (F("number" == typeof a),
            Number.isNaN(a)
              ? "NaN"
              : a === Number.POSITIVE_INFINITY
              ? "Infinity"
              : a === Number.NEGATIVE_INFINITY
              ? "-Infinity"
              : a);
      case G.STRING:
        return "" === a ? (r ? "" : void 0) : (F("string" == typeof a), a);
      case G.BOOL:
        return !1 === a ? !r && void 0 : (F("boolean" == typeof a), a);
      case G.UINT64:
      case G.FIXED64:
        F("number" == typeof a || "string" == typeof a || "bigint" == typeof a);
        let e = A.from(a);
        if (e.isZero() && !r) return;
        return e.toString();
      case G.INT64:
      case G.SFIXED64:
      case G.SINT64:
        F("number" == typeof a || "string" == typeof a || "bigint" == typeof a);
        let t = L.from(a);
        if (t.isZero() && !r) return;
        return t.toString();
      case G.BYTES:
        return (
          F(a instanceof Uint8Array),
          a.byteLength
            ? (function (e) {
                let a,
                  t = "",
                  n = 0,
                  s = 0;
                for (let r = 0; r < e.length; r++)
                  switch (((a = e[r]), n)) {
                    case 0:
                      (t += f[a >> 2]), (s = (3 & a) << 4), (n = 1);
                      break;
                    case 1:
                      (t += f[s | (a >> 4)]), (s = (15 & a) << 2), (n = 2);
                      break;
                    case 2:
                      (t += f[s | (a >> 6)]), (t += f[63 & a]), (n = 0);
                  }
                return n && ((t += f[s]), (t += "="), 1 == n && (t += "=")), t;
              })(a)
            : r
            ? ""
            : void 0
        );
    }
  }
}
function ee(e, a = q.STRING) {
  switch (e) {
    case G.BOOL:
      return !1;
    case G.UINT64:
    case G.FIXED64:
      return W(A.ZERO, a);
    case G.INT64:
    case G.SFIXED64:
    case G.SINT64:
      return W(L.ZERO, a);
    case G.DOUBLE:
    case G.FLOAT:
      return 0;
    case G.BYTES:
      return new Uint8Array(0);
    case G.STRING:
      return "";
    default:
      return 0;
  }
}
class ae {
  constructor(e) {
    this.info = e;
  }
  prepare() {
    var e;
    if (!this.fieldNoToField) {
      const a = null !== (e = this.info.fields) && void 0 !== e ? e : [];
      this.fieldNoToField = new Map(a.map((e) => [e.no, e]));
    }
  }
  read(e, a, t, n) {
    this.prepare();
    const s = void 0 === n ? e.len : e.pos + n;
    for (; e.pos < s; ) {
      const [n, s] = e.tag(),
        r = this.fieldNoToField.get(n);
      if (!r) {
        let r = t.readUnknownField;
        if ("throw" == r)
          throw new Error(
            `Unknown field ${n} (wire type ${s}) for ${this.info.typeName}`
          );
        let i = e.skip(s);
        !1 !== r && (!0 === r ? p.onRead : r)(this.info.typeName, a, n, s, i);
        continue;
      }
      let i = a,
        l = r.repeat,
        o = r.localName;
      switch (
        (r.oneof &&
          ((i = i[r.oneof]),
          i.oneofKind !== o && (i = a[r.oneof] = { oneofKind: o })),
        r.kind)
      ) {
        case "scalar":
        case "enum":
          let a = "enum" == r.kind ? G.INT32 : r.T,
            n = "scalar" == r.kind ? r.L : void 0;
          if (l) {
            let t = i[o];
            if (s == N.LengthDelimited && a != G.STRING && a != G.BYTES) {
              let s = e.uint32() + e.pos;
              for (; e.pos < s; ) t.push(this.scalar(e, a, n));
            } else t.push(this.scalar(e, a, n));
          } else i[o] = this.scalar(e, a, n);
          break;
        case "message":
          if (l) {
            let a = i[o],
              n = r.T().internalBinaryRead(e, e.uint32(), t);
            a.push(n);
          } else i[o] = r.T().internalBinaryRead(e, e.uint32(), t, i[o]);
          break;
        case "map":
          let [u, g] = this.mapEntry(r, e, t);
          i[o][u] = g;
      }
    }
  }
  mapEntry(e, a, t) {
    let n,
      s,
      r = a.uint32(),
      i = a.pos + r;
    for (; a.pos < i; ) {
      let [r, i] = a.tag();
      switch (r) {
        case 1:
          n =
            e.K == G.BOOL ? a.bool().toString() : this.scalar(a, e.K, q.STRING);
          break;
        case 2:
          switch (e.V.kind) {
            case "scalar":
              s = this.scalar(a, e.V.T, e.V.L);
              break;
            case "enum":
              s = a.int32();
              break;
            case "message":
              s = e.V.T().internalBinaryRead(a, a.uint32(), t);
          }
          break;
        default:
          throw new Error(
            `Unknown field ${r} (wire type ${i}) in map entry for ${this.info.typeName}#${e.name}`
          );
      }
    }
    if (void 0 === n) {
      let a = ee(e.K);
      n = e.K == G.BOOL ? a.toString() : a;
    }
    if (void 0 === s)
      switch (e.V.kind) {
        case "scalar":
          s = ee(e.V.T, e.V.L);
          break;
        case "enum":
          s = 0;
          break;
        case "message":
          s = e.V.T().create();
      }
    return [n, s];
  }
  scalar(e, a, t) {
    switch (a) {
      case G.INT32:
        return e.int32();
      case G.STRING:
        return e.string();
      case G.BOOL:
        return e.bool();
      case G.DOUBLE:
        return e.double();
      case G.FLOAT:
        return e.float();
      case G.INT64:
        return W(e.int64(), t);
      case G.UINT64:
        return W(e.uint64(), t);
      case G.FIXED64:
        return W(e.fixed64(), t);
      case G.FIXED32:
        return e.fixed32();
      case G.BYTES:
        return e.bytes();
      case G.UINT32:
        return e.uint32();
      case G.SFIXED32:
        return e.sfixed32();
      case G.SFIXED64:
        return W(e.sfixed64(), t);
      case G.SINT32:
        return e.sint32();
      case G.SINT64:
        return W(e.sint64(), t);
    }
  }
}
class te {
  constructor(e) {
    this.info = e;
  }
  prepare() {
    if (!this.fields) {
      const e = this.info.fields ? this.info.fields.concat() : [];
      this.fields = e.sort((e, a) => e.no - a.no);
    }
  }
  write(e, a, t) {
    this.prepare();
    for (const n of this.fields) {
      let s,
        r,
        i = n.repeat,
        l = n.localName;
      if (n.oneof) {
        const a = e[n.oneof];
        if (a.oneofKind !== l) continue;
        (s = a[l]), (r = !0);
      } else (s = e[l]), (r = !1);
      switch (n.kind) {
        case "scalar":
        case "enum":
          let e = "enum" == n.kind ? G.INT32 : n.T;
          if (i)
            if ((F(Array.isArray(s)), i == Z.PACKED))
              this.packed(a, e, n.no, s);
            else for (const t of s) this.scalar(a, e, n.no, t, !0);
          else void 0 === s ? F(n.opt) : this.scalar(a, e, n.no, s, r || n.opt);
          break;
        case "message":
          if (i) {
            F(Array.isArray(s));
            for (const e of s) this.message(a, t, n.T(), n.no, e);
          } else this.message(a, t, n.T(), n.no, s);
          break;
        case "map":
          F("object" == typeof s && null !== s);
          for (const [e, r] of Object.entries(s)) this.mapEntry(a, t, n, e, r);
      }
    }
    let n = t.writeUnknownFields;
    !1 !== n && (!0 === n ? p.onWrite : n)(this.info.typeName, e, a);
  }
  mapEntry(e, a, t, n, s) {
    e.tag(t.no, N.LengthDelimited), e.fork();
    let r = n;
    switch (t.K) {
      case G.INT32:
      case G.FIXED32:
      case G.UINT32:
      case G.SFIXED32:
      case G.SINT32:
        r = Number.parseInt(n);
        break;
      case G.BOOL:
        F("true" == n || "false" == n), (r = "true" == n);
    }
    switch ((this.scalar(e, t.K, 1, r, !0), t.V.kind)) {
      case "scalar":
        this.scalar(e, t.V.T, 2, s, !0);
        break;
      case "enum":
        this.scalar(e, G.INT32, 2, s, !0);
        break;
      case "message":
        this.message(e, a, t.V.T(), 2, s);
    }
    e.join();
  }
  message(e, a, t, n, s) {
    void 0 !== s &&
      (t.internalBinaryWrite(s, e.tag(n, N.LengthDelimited).fork(), a),
      e.join());
  }
  scalar(e, a, t, n, s) {
    let [r, i, l] = this.scalarInfo(a, n);
    (l && !s) || (e.tag(t, r), e[i](n));
  }
  packed(e, a, t, n) {
    if (!n.length) return;
    F(a !== G.BYTES && a !== G.STRING), e.tag(t, N.LengthDelimited), e.fork();
    let [, s] = this.scalarInfo(a);
    for (let a = 0; a < n.length; a++) e[s](n[a]);
    e.join();
  }
  scalarInfo(e, a) {
    let t,
      n = N.Varint,
      s = void 0 === a,
      r = 0 === a;
    switch (e) {
      case G.INT32:
        t = "int32";
        break;
      case G.STRING:
        (r = s || !a.length), (n = N.LengthDelimited), (t = "string");
        break;
      case G.BOOL:
        (r = !1 === a), (t = "bool");
        break;
      case G.UINT32:
        t = "uint32";
        break;
      case G.DOUBLE:
        (n = N.Bit64), (t = "double");
        break;
      case G.FLOAT:
        (n = N.Bit32), (t = "float");
        break;
      case G.INT64:
        (r = s || L.from(a).isZero()), (t = "int64");
        break;
      case G.UINT64:
        (r = s || A.from(a).isZero()), (t = "uint64");
        break;
      case G.FIXED64:
        (r = s || A.from(a).isZero()), (n = N.Bit64), (t = "fixed64");
        break;
      case G.BYTES:
        (r = s || !a.byteLength), (n = N.LengthDelimited), (t = "bytes");
        break;
      case G.FIXED32:
        (n = N.Bit32), (t = "fixed32");
        break;
      case G.SFIXED32:
        (n = N.Bit32), (t = "sfixed32");
        break;
      case G.SFIXED64:
        (r = s || L.from(a).isZero()), (n = N.Bit64), (t = "sfixed64");
        break;
      case G.SINT32:
        t = "sint32";
        break;
      case G.SINT64:
        (r = s || L.from(a).isZero()), (t = "sint64");
    }
    return [n, t, s || r];
  }
}
function ne(e, a, t) {
  let n,
    s,
    r = t;
  for (let t of e.fields) {
    let e = t.localName;
    if (t.oneof) {
      const i = r[t.oneof];
      if (null == (null == i ? void 0 : i.oneofKind)) continue;
      if (
        ((n = i[e]), (s = a[t.oneof]), (s.oneofKind = i.oneofKind), null == n)
      ) {
        delete s[e];
        continue;
      }
    } else if (((n = r[e]), (s = a), null == n)) continue;
    switch ((t.repeat && (s[e].length = n.length), t.kind)) {
      case "scalar":
      case "enum":
        if (t.repeat) for (let a = 0; a < n.length; a++) s[e][a] = n[a];
        else s[e] = n;
        break;
      case "message":
        let a = t.T();
        if (t.repeat)
          for (let t = 0; t < n.length; t++) s[e][t] = a.create(n[t]);
        else void 0 === s[e] ? (s[e] = a.create(n)) : a.mergePartial(s[e], n);
        break;
      case "map":
        switch (t.V.kind) {
          case "scalar":
          case "enum":
            Object.assign(s[e], n);
            break;
          case "message":
            let a = t.V.T();
            for (let t of Object.keys(n)) s[e][t] = a.create(n[t]);
        }
    }
  }
}
const se = Object.values;
function re(e, a, t) {
  if (a === t) return !0;
  if (e !== G.BYTES) return !1;
  let n = a,
    s = t;
  if (n.length !== s.length) return !1;
  for (let e = 0; e < n.length; e++) if (n[e] != s[e]) return !1;
  return !0;
}
function ie(e, a, t) {
  if (a.length !== t.length) return !1;
  for (let n = 0; n < a.length; n++) if (!re(e, a[n], t[n])) return !1;
  return !0;
}
function le(e, a, t) {
  if (a.length !== t.length) return !1;
  for (let n = 0; n < a.length; n++) if (!e.equals(a[n], t[n])) return !1;
  return !0;
}
const oe = Object.getOwnPropertyDescriptors(Object.getPrototypeOf({}));
class ue {
  constructor(e, a, t) {
    (this.defaultCheckDepth = 16),
      (this.typeName = e),
      (this.fields = a.map(H)),
      (this.options = null != t ? t : {}),
      (this.messagePrototype = Object.create(
        null,
        Object.assign(Object.assign({}, oe), { [X]: { value: this } })
      )),
      (this.refTypeCheck = new Y(this)),
      (this.refJsonReader = new _(this)),
      (this.refJsonWriter = new Q(this)),
      (this.refBinReader = new ae(this)),
      (this.refBinWriter = new te(this));
  }
  create(e) {
    let a = (function (e) {
      const a = e.messagePrototype
        ? Object.create(e.messagePrototype)
        : Object.defineProperty({}, X, { value: e });
      for (let t of e.fields) {
        let e = t.localName;
        if (!t.opt)
          if (t.oneof) a[t.oneof] = { oneofKind: void 0 };
          else if (t.repeat) a[e] = [];
          else
            switch (t.kind) {
              case "scalar":
                a[e] = ee(t.T, t.L);
                break;
              case "enum":
                a[e] = 0;
                break;
              case "map":
                a[e] = {};
            }
      }
      return a;
    })(this);
    return void 0 !== e && ne(this, a, e), a;
  }
  clone(e) {
    let a = this.create();
    return ne(this, a, e), a;
  }
  equals(e, a) {
    return (function (e, a, t) {
      if (a === t) return !0;
      if (!a || !t) return !1;
      for (let n of e.fields) {
        let e = n.localName,
          s = n.oneof ? a[n.oneof][e] : a[e],
          r = n.oneof ? t[n.oneof][e] : t[e];
        switch (n.kind) {
          case "enum":
          case "scalar":
            let e = "enum" == n.kind ? G.INT32 : n.T;
            if (!(n.repeat ? ie(e, s, r) : re(e, s, r))) return !1;
            break;
          case "map":
            if (
              !("message" == n.V.kind
                ? le(n.V.T(), se(s), se(r))
                : ie("enum" == n.V.kind ? G.INT32 : n.V.T, se(s), se(r)))
            )
              return !1;
            break;
          case "message":
            let a = n.T();
            if (!(n.repeat ? le(a, s, r) : a.equals(s, r))) return !1;
        }
      }
      return !0;
    })(this, e, a);
  }
  is(e, a = this.defaultCheckDepth) {
    return this.refTypeCheck.is(e, a, !1);
  }
  isAssignable(e, a = this.defaultCheckDepth) {
    return this.refTypeCheck.is(e, a, !0);
  }
  mergePartial(e, a) {
    ne(this, e, a);
  }
  fromBinary(e, a) {
    let t = (function (e) {
      return e ? Object.assign(Object.assign({}, D), e) : D;
    })(a);
    return this.internalBinaryRead(t.readerFactory(e), e.byteLength, t);
  }
  fromJson(e, a) {
    return this.internalJsonRead(
      e,
      (function (e) {
        return e ? Object.assign(Object.assign({}, M), e) : M;
      })(a)
    );
  }
  fromJsonString(e, a) {
    let t = JSON.parse(e);
    return this.fromJson(t, a);
  }
  toJson(e, a) {
    return this.internalJsonWrite(
      e,
      (function (e) {
        return e ? Object.assign(Object.assign({}, K), e) : K;
      })(a)
    );
  }
  toJsonString(e, a) {
    var t;
    let n = this.toJson(e, a);
    return JSON.stringify(
      n,
      null,
      null !== (t = null == a ? void 0 : a.prettySpaces) && void 0 !== t ? t : 0
    );
  }
  toBinary(e, a) {
    let t = (function (e) {
      return e ? Object.assign(Object.assign({}, P), e) : P;
    })(a);
    return this.internalBinaryWrite(e, t.writerFactory(), t).finish();
  }
  internalJsonRead(e, a, t) {
    if (null !== e && "object" == typeof e && !Array.isArray(e)) {
      let n = null != t ? t : this.create();
      return this.refJsonReader.read(e, n, a), n;
    }
    throw new Error(
      `Unable to parse message ${this.typeName} from JSON ${d(e)}.`
    );
  }
  internalJsonWrite(e, a) {
    return this.refJsonWriter.write(e, a);
  }
  internalBinaryWrite(e, a, t) {
    return this.refBinWriter.write(e, a, t), a;
  }
  internalBinaryRead(e, a, t, n) {
    let s = null != n ? n : this.create();
    return this.refBinReader.read(e, s, t, a), s;
  }
}
const ge = new (class extends ue {
  constructor() {
    super("PlayerRequest", [
      { no: 1, name: "context", kind: "message", T: () => ce },
      { no: 2, name: "videoId", kind: "scalar", opt: !0, T: 9 },
      { no: 3, name: "contentCheckOk", kind: "scalar", opt: !0, T: 8 },
      { no: 4, name: "playbackContext", kind: "message", T: () => de },
      { no: 5, name: "racyCheckOk", kind: "scalar", opt: !0, T: 8 },
    ]);
  }
})();
const ce = new (class extends ue {
  constructor() {
    super("InnerTubeContext", [
      { no: 1, name: "client", kind: "message", T: () => me },
      { no: 9, name: "adSignalsInfo", kind: "message", T: () => he },
    ]);
  }
})();
const me = new (class extends ue {
  constructor() {
    super("Client", [
      { no: 1, name: "hl", kind: "scalar", opt: !0, T: 9 },
      { no: 2, name: "gl", kind: "scalar", opt: !0, T: 9 },
      { no: 12, name: "deviceMake", kind: "scalar", T: 9 },
      { no: 13, name: "deviceModel", kind: "scalar", T: 9 },
      { no: 16, name: "clientName", kind: "scalar", T: 5 },
      { no: 17, name: "clientVersion", kind: "scalar", T: 9 },
      { no: 18, name: "osName", kind: "scalar", T: 9 },
      { no: 19, name: "osVersion", kind: "scalar", T: 9 },
      { no: 80, name: "timeZone", kind: "scalar", T: 9 },
    ]);
  }
})();
const de = new (class extends ue {
  constructor() {
    super("PlaybackContext", [
      { no: 1, name: "contentPlaybackContext", kind: "message", T: () => fe },
    ]);
  }
})();
const fe = new (class extends ue {
  constructor() {
    super("ContentPlaybackContext", [
      { no: 4, name: "id4", kind: "scalar", opt: !0, T: 5 },
      { no: 6, name: "id6", kind: "scalar", opt: !0, T: 5 },
      { no: 8, name: "id8", kind: "scalar", opt: !0, T: 5 },
      { no: 9, name: "id9", kind: "scalar", opt: !0, T: 5 },
    ]);
  }
})();
const he = new (class extends ue {
  constructor() {
    super("AdSignalsInfo", [
      { no: 1, name: "params", kind: "map", K: 9, V: { kind: "scalar", T: 9 } },
    ]);
  }
})();
const pe = new (class extends ue {
  constructor() {
    super("Browse", [
      { no: 1, name: "context", kind: "message", T: () => Ne },
      { no: 2, name: "browseId", kind: "scalar", T: 9 },
    ]);
  }
})();
const Ne = new (class extends ue {
  constructor() {
    super("Context", [
      { no: 1, name: "client", kind: "message", T: () => be },
      { no: 9, name: "adSignalsInfo", kind: "message", T: () => ye },
    ]);
  }
})();
const be = new (class extends ue {
  constructor() {
    super("Client", [
      { no: 1, name: "hl", kind: "scalar", opt: !0, T: 9 },
      { no: 2, name: "gl", kind: "scalar", opt: !0, T: 9 },
      { no: 12, name: "deviceMake", kind: "scalar", T: 9 },
      { no: 13, name: "deviceModel", kind: "scalar", T: 9 },
      { no: 16, name: "clientName", kind: "scalar", T: 5 },
      { no: 17, name: "clientVersion", kind: "scalar", T: 9 },
      { no: 18, name: "osName", kind: "scalar", T: 9 },
      { no: 19, name: "osVersion", kind: "scalar", T: 9 },
      { no: 80, name: "timeZone", kind: "scalar", T: 9 },
    ]);
  }
})();
const ye = new (class extends ue {
  constructor() {
    super("AdSignalsInfo", [
      { no: 1, name: "params", kind: "map", K: 9, V: { kind: "scalar", T: 9 } },
    ]);
  }
})();
let Te;
s("v1.5.1(1005)");
const xe = new URL($request.url);
s(`⚠ url: ${xe.toJSON()}`, "");
const Ce = $request.method,
  ke = xe.hostname,
  we = xe.pathname;
s(`⚠ METHOD: ${Ce}, HOST: ${ke}, PATH: ${we}`, "");
const Se = (
  $request.headers?.["Content-Type"] ?? $request.headers?.["content-type"]
)?.split(";")?.[0];
s(`⚠ FORMAT: ${Se}`, ""),
  (async () => {
    const { Settings: n, Caches: r, Configs: i } = m("DualSubs", "YouTube", c);
    switch ((s(`⚠ Settings.Switch: ${n?.Switch}`, ""), n.Switch)) {
      case !0:
      default:
        const i = xe.searchParams.get("subtype") ?? n.Type,
          l = [
            xe.searchParams.get("lang")?.toUpperCase?.() ?? n.Languages[0],
            (xe.searchParams.get("tlang") ?? r?.tlang)?.toUpperCase?.() ??
              n.Languages[1],
          ];
        s(`⚠ Type: ${i}, Languages: ${l}`, "");
        let o = {};
        switch (Ce) {
          case "POST":
          case "PUT":
          case "PATCH":
          case "DELETE":
            switch (Se) {
              case void 0:
              case "application/x-www-form-urlencoded":
              case "text/plain":
              default:
              case "application/x-mpegURL":
              case "application/x-mpegurl":
              case "application/vnd.apple.mpegurl":
              case "audio/mpegurl":
              case "text/xml":
              case "text/html":
              case "text/plist":
              case "application/xml":
              case "application/plist":
              case "application/x-plist":
              case "text/vtt":
              case "application/vtt":
                break;
              case "text/json":
              case "application/json":
                switch (((o = JSON.parse($request.body ?? "{}")), we)) {
                  case "/youtubei/v1/player":
                    o?.playbackContext &&
                      (s("⚠ playbackContext", ""),
                      o?.playbackContext.contentPlaybackContext &&
                        (o.playbackContext.contentPlaybackContext.autoCaptionsDefaultOn =
                          !0));
                    break;
                  case "/youtubei/v1/browse":
                    o?.browseId?.startsWith?.("MPLYt_") &&
                      xe.searchParams.set("subtype", "Translate");
                }
                $request.body = JSON.stringify(o);
                break;
              case "application/protobuf":
              case "application/x-protobuf":
              case "application/vnd.google.protobuf":
              case "application/grpc":
              case "application/grpc+proto":
              case "application/octet-stream":
                let t =
                  "Quantumult X" === e
                    ? new Uint8Array($request.bodyBytes ?? [])
                    : $request.body ?? new Uint8Array();
                switch (Se) {
                  case "application/protobuf":
                  case "application/x-protobuf":
                  case "application/vnd.google.protobuf":
                    switch (we) {
                      case "/youtubei/v1/player":
                        (o = ge.fromBinary(t)),
                          o?.playbackContext &&
                            (s("⚠ playbackContext", ""),
                            o?.playbackContext.contentPlaybackContext &&
                              ((o.playbackContext.contentPlaybackContext.id4 = 1),
                              (o.playbackContext.contentPlaybackContext.id6 = 1),
                              (o.playbackContext.contentPlaybackContext.id8 = 1),
                              (o.playbackContext.contentPlaybackContext.id9 = 1))),
                          (t = ge.toBinary(o));
                        break;
                      case "/youtubei/v1/browse":
                        (o = pe.fromBinary(t)),
                          o?.browseId?.startsWith?.("MPLYt_") &&
                            (n.Types.includes("Translate")
                              ? a.set(URL, "query.subtype", "Translate")
                              : n.Types.includes("External") &&
                                a.set(URL, "query.subtype", "External")),
                          (t = pe.toBinary(o));
                    }
                }
                $request.body = t;
            }
          case "GET":
            switch (ke) {
              case "www.youtube.com":
              case "m.youtube.com":
                if ("/api/timedtext" === we) {
                  const e = xe.searchParams.get("v"),
                    a = xe.searchParams.get("kind"),
                    i = xe.searchParams.get("lang"),
                    l = xe.searchParams.get("tlang");
                  if (
                    (s(`⚠ v: ${e}, kind: ${a}, lang: ${i}, tlang: ${l}`, ""),
                    !l)
                  )
                    switch (
                      (s("⚠ 翻译语言：未指定", ""),
                      e &&
                        i &&
                        (r.Playlists.Subtitle.set(e, i),
                        (r.Playlists.Subtitle = (function (e, a = 100) {
                          return (
                            console.log(`☑️ Set Cache, cacheSize: ${a}`, ""),
                            (e = (e = Array.from(e || [])).slice(-a)),
                            console.log("✅ Set Cache", ""),
                            e
                          );
                        })(r?.Playlists.Subtitle, n.CacheSize)),
                        t.setItem(
                          "@DualSubs.Composite.Caches.Playlists.Subtitle",
                          r.Playlists.Subtitle
                        )),
                      n.AutoCC)
                    ) {
                      case !0:
                      default:
                        s("⚠ 自动翻译字幕：开启", ""),
                          r.tlang &&
                            r.tlang !== i &&
                            xe.searchParams.set("tlang", r.tlang);
                        if (xe.searchParams.get("tlang") == "zh-Hant"){
                            xe.searchParams.set("tlang", "zh-Hans");
                        }
                        break;
                      case !1:
                        s("⚠ 自动翻译字幕：关闭", "");
                    }
                  if (xe.searchParams.get("tlang"))
                    switch (
                      (s("⚠ 翻译语言：已指定", ""),
                      (r.tlang = xe.searchParams.get("tlang")),
                      t.setItem("@DualSubs.YouTube.Caches.tlang", r.tlang),
                      n.Type)
                    ) {
                      case "Composite":
                      case "Official":
                      default:
                        if (xe.searchParams.get("tlang") == "zh-Hant"){
                            xe.searchParams.set("tlang", "zh-Hans");
                        }
                        s("⚠ 官方字幕：合成器", ""),
                          i?.split?.(/[-_]/)?.[0] ===
                            xe.searchParams
                              .get("tlang")
                              ?.split?.(/[-_]/)?.[0] && (n.ShowOnly = !0),
                          n.ShowOnly ||
                            xe.searchParams.set("subtype", "Official");
                        break;
                      case "Translate":
                        s("⚠ 翻译字幕：翻译器", ""),
                          xe.searchParams.delete("tlang"),
                          xe.searchParams.set("subtype", "Translate");
                        if (xe.searchParams.get("hl") == "zh-TW"){
                            xe.searchParams.set("hl", "zh-CN");
                        }
                        break;
                      case "External":
                        s("⚠ 外部字幕：外部源", ""),
                          xe.searchParams.delete("tlang"),
                          xe.searchParams.set("subtype", "External");
                    }
                }
            }
        }
        ($request.url = xe.toString()),
          s("🚧 调试信息", `$request.url: ${$request.url}`, "");
      case !1:
    }
  })()
    .catch((a) =>
      (function (a) {
        switch (e) {
          case "Surge":
          case "Loon":
          case "Stash":
          case "Egern":
          case "Shadowrocket":
          case "Quantumult X":
          default:
            s("", "❗️执行错误!", a, "");
            break;
          case "Node.js":
            s("", "❗️执行错误!", a.stack, "");
        }
      })(a)
    )
    .finally(() => {
      if (void 0 === Te) n($request);
      else if ((Te.headers, Te.headers, "Quantumult X" === e))
        Te.status || (Te.status = "HTTP/1.1 200 OK"),
          delete Te.headers?.["Content-Length"],
          delete Te.headers?.["content-length"],
          delete Te.headers?.["Transfer-Encoding"],
          n(Te);
      else n({ response: Te });
    });
